summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmirsaman Memaripour <amirsaman.memaripour@mongodb.com>2020-04-06 13:34:00 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-04-23 19:16:00 +0000
commit6f247fbcd154b1026ffaf5223584030b529a0e51 (patch)
tree1ff5fb9aab75e24a132fc96c4a46c43fc6765996
parent53d4c320668a0b880081c68836951259853c8364 (diff)
downloadmongo-6f247fbcd154b1026ffaf5223584030b529a0e51.tar.gz
SERVER-46942 Cancel timer before leaving onAcquireConn
Avoid leaking state information if server closes too quickly on network_interface_tl. (cherry picked from commit b43425cf31637d9f2dfd35eb7b09d372631e09fb)
-rw-r--r--src/mongo/executor/network_interface_tl.cpp17
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));
});
}