diff options
author | Amirsaman Memaripour <amirsaman.memaripour@mongodb.com> | 2020-04-06 13:34:00 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-07 16:42:02 +0000 |
commit | b43425cf31637d9f2dfd35eb7b09d372631e09fb (patch) | |
tree | f51c650142f942fb40d17c7878f9abe02b00df86 | |
parent | 4a806ff563725af9f36d115eeb5a99c7750f17c7 (diff) | |
download | mongo-b43425cf31637d9f2dfd35eb7b09d372631e09fb.tar.gz |
SERVER-46942 Cancel timer before leaving onAcquireConn
Avoid leaking state information if server closes too quickly on network_interface_tl.
-rw-r--r-- | src/mongo/executor/network_interface_tl.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/mongo/executor/network_interface_tl.cpp b/src/mongo/executor/network_interface_tl.cpp index 1872e5322e7..1dfbf7b3300 100644 --- a/src/mongo/executor/network_interface_tl.cpp +++ b/src/mongo/executor/network_interface_tl.cpp @@ -438,6 +438,11 @@ void NetworkInterfaceTL::_onAcquireConn(std::shared_ptr<CommandState> state, return RemoteCommandOnAnyResponse(target, std::move(response)); }) .getAsync([this, state, baton](StatusWith<RemoteCommandOnAnyResponse> swr) { + // Cancel `state->timer` before returning to prevent leaking `state`. + if (state->timer) { + state->timer->cancel(baton); + } + if (!swr.isOK()) { state->conn->indicateFailure(swr.getStatus()); } else if (!swr.getValue().isOK()) { @@ -460,10 +465,6 @@ void NetworkInterfaceTL::_onAcquireConn(std::shared_ptr<CommandState> state, } } - if (state->timer) { - state->timer->cancel(baton); - } - state->promise.setFromStatusWith(std::move(swr)); }); } |