summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Broadstone <mbroadst@gmail.com>2018-01-02 12:39:11 -0500
committerJonathan Reams <jbreams@mongodb.com>2018-04-05 11:42:32 -0400
commit11fabe4f8295da18f68aae8a877c38a48c1b5133 (patch)
tree527e62b8c46f6c8edbefc23d61b2d31ad814c56a
parentffe04b5ef2ac3f5ca0061db6071779f329c2e23f (diff)
downloadmongo-11fabe4f8295da18f68aae8a877c38a48c1b5133.tar.gz
SERVER-32477 Gracefully shutdown sockets in ASIOSession
We were depending on the dtor for the basic_stream_socket to gracefully shutdown the socket on destruction, however this is broken on OSX. Instead we need to explicitly shutdown the socket (the asio docs indicate that this is the most "portable" solution). (cherry picked from commit 4108212bffdad96a5be22e2fc71038f48d8740a4)
-rw-r--r--src/mongo/transport/session_asio.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/mongo/transport/session_asio.h b/src/mongo/transport/session_asio.h
index 00e137d0cfb..250969f6f5d 100644
--- a/src/mongo/transport/session_asio.h
+++ b/src/mongo/transport/session_asio.h
@@ -75,6 +75,10 @@ public:
}
}
+ ~ASIOSession() {
+ shutdown();
+ }
+
TransportLayer* getTransportLayer() const override {
return _tl;
}
@@ -97,11 +101,13 @@ public:
}
void shutdown() {
- std::error_code ec;
- getSocket().cancel();
- getSocket().shutdown(GenericSocket::shutdown_both, ec);
- if (ec) {
- error() << "Error closing socket: " << ec.message();
+ if (getSocket().is_open()) {
+ std::error_code ec;
+ getSocket().cancel();
+ getSocket().shutdown(GenericSocket::shutdown_both, ec);
+ if (ec) {
+ error() << "Error shutting down socket: " << ec.message();
+ }
}
}