Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigItem: Fix infinite recursion caused by ignore_on_error when … #9406

Merged
merged 2 commits into from
Oct 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/config/configitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,9 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
<< "Committing " << items.size() << " new items.";
#endif /* I2_DEBUG */

for (const auto& ip : items)
newItems.push_back(ip.first);

std::set<Type::Ptr> types;
std::set<Type::Ptr> completed_types;
int itemsCount {0};

for (const Type::Ptr& type : Type::GetAllTypes()) {
if (ConfigObject::TypeInstance->IsAssignableFrom(type))
Expand All @@ -464,18 +462,32 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
continue;

std::atomic<int> committed_items(0);
upq.ParallelFor(items, [&type, &committed_items](const ItemPair& ip) {
std::mutex newItemsMutex;

upq.ParallelFor(items, [&type, &committed_items, &newItems, &newItemsMutex](const ItemPair& ip) {
const ConfigItem::Ptr& item = ip.first;

if (item->m_Type != type)
return;

ip.first->Commit(ip.second);
if (!item->Commit(ip.second)) {
if (item->IsIgnoreOnError()) {
item->Unregister();
}

return;
}

committed_items++;

std::unique_lock<std::mutex> lock(newItemsMutex);
newItems.emplace_back(item);
});

upq.Join();

itemsCount += committed_items;

completed_types.insert(type);

#ifdef I2_DEBUG
Expand All @@ -491,7 +503,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue

#ifdef I2_DEBUG
Log(LogDebug, "configitem")
<< "Committed " << items.size() << " items.";
<< "Committed " << itemsCount << " items.";
#endif /* I2_DEBUG */

completed_types.clear();
Expand Down