diff options
-rw-r--r-- | src/mongo/executor/network_interface_tl.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/mongo/executor/network_interface_tl.cpp b/src/mongo/executor/network_interface_tl.cpp index ec2382ea209..58d18efe0b4 100644 --- a/src/mongo/executor/network_interface_tl.cpp +++ b/src/mongo/executor/network_interface_tl.cpp @@ -404,8 +404,17 @@ void NetworkInterfaceTL::_onAcquireConn(std::shared_ptr<CommandState> state, state->conn->indicateSuccess(); } - if (state->done.swap(true)) { - return; + { + ON_BLOCK_EXIT([state, baton] { + // Cancel `state->timer` before returning to prevent leaking `state`. + if (state->timer) { + state->timer->cancel(baton); + } + }); + + if (state->done.swap(true)) { + return; + } } if (getTestCommandsEnabled()) { @@ -417,10 +426,6 @@ void NetworkInterfaceTL::_onAcquireConn(std::shared_ptr<CommandState> state, } } - if (state->timer) { - state->timer->cancel(baton); - } - state->promise.setFromStatusWith(std::move(swr)); }); } |