From c054cddfe54ebd09a505c293cc0e3b3cd761faf1 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 26 Apr 2019 18:31:24 +0200 Subject: [PATCH] fix race in _batchPingTimer shutdown (#8801) --- arangod/Replication/InitialSyncer.cpp | 18 ++++++++++++------ arangod/Replication/InitialSyncer.h | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/arangod/Replication/InitialSyncer.cpp b/arangod/Replication/InitialSyncer.cpp index cc9bf91d85..021971ea55 100644 --- a/arangod/Replication/InitialSyncer.cpp +++ b/arangod/Replication/InitialSyncer.cpp @@ -54,13 +54,19 @@ void InitialSyncer::startRecurringBatchExtension() { if (secs < 30) { secs = 30; } + + std::weak_ptr self(shared_from_this()); _batchPingTimer = SchedulerFeature::SCHEDULER->queueDelay( - RequestLane::SERVER_REPLICATION, std::chrono::seconds(secs), [this](bool cancelled) { - if (!cancelled && _batch.id != 0 && !isAborted()) { - _batch.extend(_state.connection, _progress); - startRecurringBatchExtension(); - } else { - _batchPingTimer.reset(); + RequestLane::SERVER_REPLICATION, std::chrono::seconds(secs), [self](bool cancelled) { + if (!cancelled) { + auto syncer = self.lock(); + if (syncer) { + InitialSyncer* s = static_cast(syncer.get()); + if (s->_batch.id != 0 && !s->isAborted()) { + s->_batch.extend(s->_state.connection, s->_progress); + s->startRecurringBatchExtension(); + } + } } }); } diff --git a/arangod/Replication/InitialSyncer.h b/arangod/Replication/InitialSyncer.h index cf09412781..e82cbead31 100644 --- a/arangod/Replication/InitialSyncer.h +++ b/arangod/Replication/InitialSyncer.h @@ -94,6 +94,7 @@ class InitialSyncer : public Syncer { protected: replutils::BatchInfo _batch; replutils::ProgressInfo _progress; + /// recurring task to keep the batch alive Scheduler::WorkHandle _batchPingTimer; };