Skip to content

Commit

Permalink
SERVER-24058 make connpool asio use setup timeouts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hanumantmk committed May 6, 2016
1 parent ea4e60d commit ca2702e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion jstests/sharding/startup_with_all_configs_down.js
Expand Up @@ -56,7 +56,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++) {
Expand Down
1 change: 0 additions & 1 deletion src/mongo/executor/async_stream_common.h
Expand Up @@ -76,7 +76,6 @@ void readStream(ASIOStream* stream,

template <typename ASIOStream>
void cancelStream(ASIOStream* stream, bool connected) {
invariant(connected);
stream->cancel();
}

Expand Down
10 changes: 8 additions & 2 deletions src/mongo/executor/connection_pool_asio.cpp
Expand Up @@ -185,7 +185,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());
});
Expand All @@ -202,7 +208,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),
Expand Down

0 comments on commit ca2702e

Please sign in to comment.