@@ -4336,7 +4336,7 @@ Result ClusterInfo::ensureIndexCoordinatorInner(LogicalCollection const& collect
4336
4336
// This object watches whether the collection is still present in Plan
4337
4337
// It assumes that the collection *is* present and only changes state
4338
4338
// if the collection disappears
4339
- CollectionWatcher collectionWatcher (_agencyCallbackRegistry, collection);
4339
+ auto collectionWatcher = std::make_shared<CollectionWatcher> (_agencyCallbackRegistry, collection);
4340
4340
4341
4341
if (!result.successful ()) {
4342
4342
if (result.httpCode () == rest::ResponseCode::PRECONDITION_FAILED) {
@@ -4437,7 +4437,7 @@ Result ClusterInfo::ensureIndexCoordinatorInner(LogicalCollection const& collect
4437
4437
}
4438
4438
}
4439
4439
4440
- if (!collectionWatcher. isPresent ()) {
4440
+ if (!collectionWatcher-> isPresent ()) {
4441
4441
return Result (TRI_ERROR_ARANGO_INDEX_CREATION_FAILED,
4442
4442
" Collection " + collectionID +
4443
4443
" has gone from database " + databaseName +
@@ -4524,7 +4524,7 @@ Result ClusterInfo::ensureIndexCoordinatorInner(LogicalCollection const& collect
4524
4524
// when we wanted to roll back the index creation.
4525
4525
}
4526
4526
4527
- if (!collectionWatcher. isPresent ()) {
4527
+ if (!collectionWatcher-> isPresent ()) {
4528
4528
return Result (TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
4529
4529
" collection " + collectionID +
4530
4530
" appears to have been dropped from database " +
@@ -6164,9 +6164,10 @@ CollectionWatcher::CollectionWatcher(AgencyCallbackRegistry* agencyCallbackRegis
6164
6164
6165
6165
_agencyCallback = std::make_shared<AgencyCallback>(
6166
6166
collection.vocbase ().server (), where,
6167
- [this ](VPackSlice const & result) {
6168
- if (result.isNone ()) {
6169
- _present.store (false );
6167
+ [self = weak_from_this ()](VPackSlice const & result) {
6168
+ auto watcher = self.lock ();
6169
+ if (result.isNone () && watcher) {
6170
+ watcher->_present .store (false );
6170
6171
}
6171
6172
return true ;
6172
6173
},
0 commit comments