Skip to content

Commit

Permalink
IcingaDB: Don't sync partially initialised objects
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Sep 11, 2024
1 parent 8beb0b7 commit a13f571
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/icingadb/icingadb-objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,27 @@ std::vector<std::vector<intrusive_ptr<ConfigObject>>> IcingaDB::ChunkObjects(std

chunks.reserve((std::distance(offset, end) + chunkSize - 1) / chunkSize);

auto emplaceChunk ([&chunks](decltype(objects)::const_iterator from, decltype(objects)::const_iterator to) {
chunks.emplace_back(std::vector<ConfigObject::Ptr>());

// If we encounter not yet activated objects, i.e. they are currently being loaded and are about to
// be activated, but are still partially initialised, we want to exclude them from the config dump
// before we end up in a nullptr deference and crash the Icinga 2 process. Should these excluded objects
// later reach the activation process, they will be captured via the `OnActiveChanged` event and processed
// in IcingaDB::VersionChangedHandler() as runtime updates.
std::copy_if(from, to, std::back_inserter(chunks.back()), [](const ConfigObject::Ptr& obj) {
return obj->IsActive();
});
});

while (std::distance(offset, end) >= chunkSize) {
auto until (offset + chunkSize);
chunks.emplace_back(offset, until);
emplaceChunk(offset, until);
offset = until;
}

if (offset != end) {
chunks.emplace_back(offset, end);
emplaceChunk(offset, end);
}

return chunks;
Expand Down

0 comments on commit a13f571

Please sign in to comment.