summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2016-05-05 14:00:43 -0400
committerJason Carey <jcarey@argv.me>2016-05-10 11:19:08 -0400
commit9afe9f3230eadb9d91a2866bf48023e074f76418 (patch)
treee9c066aec5f7570f9b2c36419d11f8e936bc0f53
parent6b20d5cb585d2d6bfde8a5961e615eab0819b35a (diff)
downloadmongo-9afe9f3230eadb9d91a2866bf48023e074f76418.tar.gz
SERVER-24058 make connpool asio use setup timeouts
We were ignoring passed setup timeouts, which caused connection acquisition to hang forever in connect if the other side didn't accept or refuse a connection. (cherry picked from commit ca2702ed79eb5f2fe5169495557a10d0b68fd0c0)
-rw-r--r--jstests/sharding/startup_with_all_configs_down.js4
-rw-r--r--src/mongo/executor/async_stream_common.h1
-rw-r--r--src/mongo/executor/connection_pool_asio.cpp10
3 files changed, 11 insertions, 4 deletions
diff --git a/jstests/sharding/startup_with_all_configs_down.js b/jstests/sharding/startup_with_all_configs_down.js
index 61bff427580..3b577b9ebe4 100644
--- a/jstests/sharding/startup_with_all_configs_down.js
+++ b/jstests/sharding/startup_with_all_configs_down.js
@@ -48,7 +48,9 @@
var error = assert.throws(function() {
st.s.getDB('test').foo.find().itcount();
});
- assert.eq(ErrorCodes.ExceededTimeLimit, error.code);
+
+ assert(ErrorCodes.ReplicaSetNotFound == error.code ||
+ ErrorCodes.ExceededTimeLimit == error.code || ErrorCodes.HostUnreachable == error.code);
jsTestLog("Restarting the config servers");
for (var i = 0; i < st._configServers.length; i++) {
diff --git a/src/mongo/executor/async_stream_common.h b/src/mongo/executor/async_stream_common.h
index a19be37ca0d..059cad53b9f 100644
--- a/src/mongo/executor/async_stream_common.h
+++ b/src/mongo/executor/async_stream_common.h
@@ -76,7 +76,6 @@ void readStream(ASIOStream* stream,
template <typename ASIOStream>
void cancelStream(ASIOStream* stream, bool connected) {
- invariant(connected);
stream->cancel();
}
diff --git a/src/mongo/executor/connection_pool_asio.cpp b/src/mongo/executor/connection_pool_asio.cpp
index b2344b54ffa..92ac06e14b9 100644
--- a/src/mongo/executor/connection_pool_asio.cpp
+++ b/src/mongo/executor/connection_pool_asio.cpp
@@ -183,7 +183,13 @@ void ASIOConnection::cancelTimeout() {
void ASIOConnection::setup(Milliseconds timeout, SetupCallback cb) {
_impl->strand().dispatch([this, timeout, cb] {
- _setupCallback = std::move(cb);
+ _setupCallback = [this, cb](ConnectionInterface* ptr, Status status) {
+ cancelTimeout();
+ cb(ptr, status);
+ };
+
+ // Actually timeout setup
+ setTimeout(timeout, [this] { _impl->connection().stream().cancel(); });
_global->_impl->_connect(_impl.get());
});
@@ -200,7 +206,7 @@ void ASIOConnection::refresh(Milliseconds timeout, RefreshCallback cb) {
_refreshCallback = std::move(cb);
// Actually timeout refreshes
- setTimeout(timeout, [this]() { _impl->connection().stream().cancel(); });
+ setTimeout(timeout, [this] { _impl->connection().stream().cancel(); });
// Our pings are isMaster's
auto beginStatus = op->beginCommand(makeIsMasterRequest(this),