diff options
author | Jonathan Reams <jbreams@mongodb.com> | 2017-12-08 16:37:23 -0500 |
---|---|---|
committer | Jonathan Reams <jbreams@mongodb.com> | 2017-12-12 10:37:23 -0500 |
commit | 9dc34426570cc57cfdb4b6f6ea4f31018662082f (patch) | |
tree | 4b089e56b5dc5c04b51b4063309a90635a434b9a /src | |
parent | f7b89ae89514673770f558456d15cb46581c3be5 (diff) | |
download | mongo-9dc34426570cc57cfdb4b6f6ea4f31018662082f.tar.gz |
SERVER-32216 Remove UNIX sockets on clean shutdown
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/shell/shell_utils.cpp | 8 | ||||
-rw-r--r-- | src/mongo/transport/transport_layer_asio.cpp | 17 | ||||
-rw-r--r-- | src/mongo/transport/transport_layer_asio.h | 2 | ||||
-rw-r--r-- | src/mongo/util/net/sockaddr.cpp | 8 | ||||
-rw-r--r-- | src/mongo/util/net/sockaddr.h | 1 |
5 files changed, 29 insertions, 7 deletions
diff --git a/src/mongo/shell/shell_utils.cpp b/src/mongo/shell/shell_utils.cpp index ad3b441d7c7..c13f6291636 100644 --- a/src/mongo/shell/shell_utils.cpp +++ b/src/mongo/shell/shell_utils.cpp @@ -222,6 +222,13 @@ BSONObj interpreterVersion(const BSONObj& a, void* data) { return BSON("" << getGlobalScriptEngine()->getInterpreterVersionString()); } +BSONObj fileExistsJS(const BSONObj& a, void*) { + uassert(40678, + "fileExists expects one string argument", + a.nFields() == 1 && a.firstElement().type() == String); + return BSON("" << fileExists(a.firstElement().valuestrsafe())); +} + void installShellUtils(Scope& scope) { scope.injectNative("getMemInfo", JSGetMemInfo); scope.injectNative("_replMonitorStats", replMonitorStats); @@ -231,6 +238,7 @@ void installShellUtils(Scope& scope) { scope.injectNative("interpreterVersion", interpreterVersion); scope.injectNative("getBuildInfo", getBuildInfo); scope.injectNative("computeSHA256Block", computeSHA256Block); + scope.injectNative("fileExists", fileExistsJS); #ifndef MONGO_SAFE_SHELL // can't launch programs diff --git a/src/mongo/transport/transport_layer_asio.cpp b/src/mongo/transport/transport_layer_asio.cpp index b1dd15f57d7..d471cdeb20a 100644 --- a/src/mongo/transport/transport_layer_asio.cpp +++ b/src/mongo/transport/transport_layer_asio.cpp @@ -199,7 +199,7 @@ Status TransportLayerASIO::setup() { } } #endif - _acceptors.emplace_back(std::move(acceptor)); + _acceptors.emplace_back(std::make_pair(std::move(addr), std::move(acceptor))); } } @@ -244,8 +244,8 @@ Status TransportLayerASIO::start() { }); for (auto& acceptor : _acceptors) { - acceptor.listen(serverGlobalParams.listenBacklog); - _acceptConnection(acceptor); + acceptor.second.listen(serverGlobalParams.listenBacklog); + _acceptConnection(acceptor.second); } const char* ssl = ""; @@ -266,7 +266,16 @@ void TransportLayerASIO::shutdown() { // Loop through the acceptors and cancel their calls to async_accept. This will prevent new // connections from being opened. for (auto& acceptor : _acceptors) { - acceptor.cancel(); + acceptor.second.cancel(); + auto& addr = acceptor.first; + if (addr.getType() == AF_UNIX && !addr.isAnonymousUNIXSocket()) { + auto path = addr.getAddr(); + log() << "removing socket file: " << path; + if (::unlink(path.c_str()) != 0) { + const auto ewd = errnoWithDescription(); + warning() << "Unable to remove UNIX socket " << path << ": " << ewd; + } + } } // If the listener thread is joinable (that is, we created/started a listener thread), then diff --git a/src/mongo/transport/transport_layer_asio.h b/src/mongo/transport/transport_layer_asio.h index 11cc43e489f..984c343b5f3 100644 --- a/src/mongo/transport/transport_layer_asio.h +++ b/src/mongo/transport/transport_layer_asio.h @@ -157,7 +157,7 @@ private: SSLParams::SSLModes _sslMode; #endif - std::vector<GenericAcceptor> _acceptors; + std::vector<std::pair<SockAddr, GenericAcceptor>> _acceptors; // Only used if _listenerOptions.async is false. stdx::thread _listenerThread; diff --git a/src/mongo/util/net/sockaddr.cpp b/src/mongo/util/net/sockaddr.cpp index ad3654e5507..6b441390d1c 100644 --- a/src/mongo/util/net/sockaddr.cpp +++ b/src/mongo/util/net/sockaddr.cpp @@ -231,6 +231,10 @@ bool SockAddr::isDefaultRoute() const { } } +bool SockAddr::isAnonymousUNIXSocket() const { + return ((getType() == AF_UNIX) && (as<sockaddr_un>().sun_path[0] == '\0')); +} + std::string SockAddr::toString(bool includePort) const { if (includePort && (getType() != AF_UNIX) && (getType() != AF_UNSPEC)) { StringBuilder ss; @@ -281,8 +285,8 @@ std::string SockAddr::getAddr() const { } case AF_UNIX: - return (as<sockaddr_un>().sun_path[0] != '\0' ? as<sockaddr_un>().sun_path - : "anonymous unix socket"); + return (!isAnonymousUNIXSocket() ? as<sockaddr_un>().sun_path + : "anonymous unix socket"); case AF_UNSPEC: return "(NONE)"; default: diff --git a/src/mongo/util/net/sockaddr.h b/src/mongo/util/net/sockaddr.h index db02dd73773..c91887f245c 100644 --- a/src/mongo/util/net/sockaddr.h +++ b/src/mongo/util/net/sockaddr.h @@ -133,6 +133,7 @@ struct SockAddr { bool isLocalHost() const; bool isDefaultRoute() const; + bool isAnonymousUNIXSocket() const; bool operator==(const SockAddr& r) const; |