From 8d3fdc2184e07cbc5b46d297c02bf88f5c2e8c42 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Fri, 26 May 2023 15:40:09 +0000 Subject: Prevent possible deadlock when calling State::cancel by dropping the taskList lock first. --- .../proton/common/scheduled_forward_executor.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/searchcore/src/vespa/searchcore/proton/common/scheduled_forward_executor.cpp b/searchcore/src/vespa/searchcore/proton/common/scheduled_forward_executor.cpp index f19ff36dbfb..230ff922e80 100644 --- a/searchcore/src/vespa/searchcore/proton/common/scheduled_forward_executor.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/scheduled_forward_executor.cpp @@ -95,11 +95,15 @@ ScheduledForwardExecutor::~ScheduledForwardExecutor() { bool ScheduledForwardExecutor::cancel(uint64_t key) { - std::lock_guard guard(_lock); - auto found = _taskList.find(key); - if (found == _taskList.end()) return false; - found->second->cancel(); - _taskList.erase(found); + std::unique_ptr state; + { + std::lock_guard guard(_lock); + auto found = _taskList.find(key); + if (found == _taskList.end()) return false; + state = std::move(found->second); + _taskList.erase(found); + } + state->cancel(); return true; } -- cgit v1.2.3