summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Midvidy <amidvidy@gmail.com>2015-11-11 13:56:42 -0500
committerAdam Midvidy <amidvidy@gmail.com>2015-11-12 00:51:32 -0500
commit0892687880f0500a5cd07e71d7c667590607ea17 (patch)
tree01303fc260c8f9e46734d372e76632522054adff
parent8dee1e3b48531f843e055d445dd545e75db30096 (diff)
downloadmongo-0892687880f0500a5cd07e71d7c667590607ea17.tar.gz
SERVER-21108 don't call cancel on destroyed timers
-rw-r--r--src/mongo/executor/connection_pool.cpp3
-rw-r--r--src/mongo/executor/connection_pool_asio.cpp20
2 files changed, 14 insertions, 9 deletions
diff --git a/src/mongo/executor/connection_pool.cpp b/src/mongo/executor/connection_pool.cpp
index 169caef2e38..a6b39841826 100644
--- a/src/mongo/executor/connection_pool.cpp
+++ b/src/mongo/executor/connection_pool.cpp
@@ -460,8 +460,7 @@ void ConnectionPool::SpecificPool::fulfillRequests(stdx::unique_lock<stdx::mutex
conn->cancelTimeout();
if (!conn->isHealthy()) {
- log() << "dropping unhealthy pooled connection to " << conn->getHostAndPort().host()
- << ":" << conn->getHostAndPort().port();
+ log() << "dropping unhealthy pooled connection to " << conn->getHostAndPort();
if (_readyPool.empty()) {
log() << "after drop, pool was empty, going to spawn some connections";
diff --git a/src/mongo/executor/connection_pool_asio.cpp b/src/mongo/executor/connection_pool_asio.cpp
index 6a9065faef3..2b475016057 100644
--- a/src/mongo/executor/connection_pool_asio.cpp
+++ b/src/mongo/executor/connection_pool_asio.cpp
@@ -48,7 +48,8 @@ ASIOTimer::ASIOTimer(asio::io_service::strand* strand)
_callbackSharedState(std::make_shared<CallbackSharedState>()) {}
ASIOTimer::~ASIOTimer() {
- cancelTimeout();
+ stdx::lock_guard<stdx::mutex> lk(_callbackSharedState->mutex);
+ ++_callbackSharedState->id;
}
void ASIOTimer::setTimeout(Milliseconds timeout, TimeoutCallback cb) {
@@ -90,12 +91,17 @@ void ASIOTimer::setTimeout(Milliseconds timeout, TimeoutCallback cb) {
}
void ASIOTimer::cancelTimeout() {
- _strand->dispatch([this] {
- {
- stdx::lock_guard<stdx::mutex> lk(_callbackSharedState->mutex);
- _callbackSharedState->id++;
- }
-
+ decltype(_callbackSharedState) sharedState;
+ decltype(_callbackSharedState->id) id;
+ {
+ stdx::lock_guard<stdx::mutex> lk(_callbackSharedState->mutex);
+ id = ++_callbackSharedState->id;
+ sharedState = _callbackSharedState;
+ }
+ _strand->dispatch([this, id, sharedState] {
+ stdx::lock_guard<stdx::mutex> lk(sharedState->mutex);
+ if (sharedState->id != id)
+ return;
_impl.cancel();
});
}