mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00
[core] Fix the risk of iterator invalidation issue. (#20989)
We erase the elements from object_id_refs_ in the method `RemoveLocalReferenceInternal()` which may cause iterator invalidation issue. Note that, normally flatmap will not trigger any iterator invalidation except triggering `rehash()`. But in this case, we may remove other elements(not only the current iterator), so there is still a risk of it.
This commit is contained in:
parent
3a5dd9a10b
commit
a3bf1af10e
1 changed files with 5 additions and 1 deletions
|
@ -256,11 +256,15 @@ void ReferenceCounter::SetNestedRefInUseRecursive(ReferenceTable::iterator inner
|
|||
|
||||
void ReferenceCounter::ReleaseAllLocalReferences() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
std::vector<ObjectID> refs_to_remove;
|
||||
for (auto &ref : object_id_refs_) {
|
||||
for (int i = ref.second.local_ref_count; i > 0; --i) {
|
||||
RemoveLocalReferenceInternal(ref.first, nullptr);
|
||||
refs_to_remove.push_back(ref.first);
|
||||
}
|
||||
}
|
||||
for (const auto &object_id_to_remove : refs_to_remove) {
|
||||
RemoveLocalReferenceInternal(object_id_to_remove, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void ReferenceCounter::RemoveLocalReference(const ObjectID &object_id,
|
||||
|
|
Loading…
Add table
Reference in a new issue