diff options
author | Matt Broadstone <mbroadst@gmail.com> | 2018-01-02 12:39:11 -0500 |
---|---|---|
committer | Jonathan Reams <jbreams@mongodb.com> | 2018-04-05 11:42:32 -0400 |
commit | 11fabe4f8295da18f68aae8a877c38a48c1b5133 (patch) | |
tree | 527e62b8c46f6c8edbefc23d61b2d31ad814c56a | |
parent | ffe04b5ef2ac3f5ca0061db6071779f329c2e23f (diff) | |
download | mongo-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.h | 16 |
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(); + } } } |