From 427647f7cea35a782f3532c02d3e16323c4aea99 Mon Sep 17 00:00:00 2001 From: Yves Duhem Date: Thu, 17 Aug 2017 09:57:54 -0400 Subject: Revert "SERVER-30588 Bind all addresses returned by getaddroinfo()" This reverts commit 1158a6b9b1de13ef2dd809b4515d881422163b5e. --- src/mongo/transport/transport_layer_asio.cpp | 75 ++++++++++++---------------- 1 file changed, 33 insertions(+), 42 deletions(-) (limited to 'src/mongo/transport') diff --git a/src/mongo/transport/transport_layer_asio.cpp b/src/mongo/transport/transport_layer_asio.cpp index 9751c49eddb..15220f3abc4 100644 --- a/src/mongo/transport/transport_layer_asio.cpp +++ b/src/mongo/transport/transport_layer_asio.cpp @@ -165,61 +165,52 @@ Status TransportLayerASIO::setup() { warning() << "Skipping empty bind address"; continue; } - - const auto addrs = SockAddr::createAll( - ip, _listenerOptions.port, _listenerOptions.enableIPv6 ? AF_UNSPEC : AF_INET); - if (addrs.empty()) { - warning() << "Found no addresses for " << ip; - continue; - } - - for (const auto& addr : addrs) { - asio::generic::stream_protocol::endpoint endpoint(addr.raw(), addr.addressSize); + SockAddr addr(StringData(ip), + _listenerOptions.port, + _listenerOptions.enableIPv6 ? AF_UNSPEC : AF_INET); + asio::generic::stream_protocol::endpoint endpoint(addr.raw(), addr.addressSize); #ifndef _WIN32 - if (addr.getType() == AF_UNIX) { - if (::unlink(ip.c_str()) == -1 && errno != ENOENT) { - error() << "Failed to unlink socket file " << ip << " " - << errnoWithDescription(errno); - fassertFailedNoTrace(40486); - } + if (addr.getType() == AF_UNIX) { + if (::unlink(ip.c_str()) == -1 && errno != ENOENT) { + error() << "Failed to unlink socket file " << ip << " " + << errnoWithDescription(errno); + fassertFailedNoTrace(40486); } + } #endif - if (addr.getType() == AF_INET6 && !_listenerOptions.enableIPv6) { - error() << "Specified ipv6 bind address, but ipv6 is disabled"; - fassertFailedNoTrace(40488); - } + if (addr.getType() == AF_INET6 && !_listenerOptions.enableIPv6) { + error() << "Specified ipv6 bind address, but ipv6 is disabled"; + fassertFailedNoTrace(40488); + } - GenericAcceptor acceptor(*_ioContext); - acceptor.open(endpoint.protocol()); - acceptor.set_option(GenericAcceptor::reuse_address(true)); + GenericAcceptor acceptor(*_ioContext); + acceptor.open(endpoint.protocol()); + acceptor.set_option(GenericAcceptor::reuse_address(true)); - acceptor.non_blocking(true, ec); - if (ec) { - return errorCodeToStatus(ec); - } + acceptor.non_blocking(true, ec); + if (ec) { + return errorCodeToStatus(ec); + } - acceptor.bind(endpoint, ec); - if (ec) { - return errorCodeToStatus(ec); - } + acceptor.bind(endpoint, ec); + if (ec) { + return errorCodeToStatus(ec); + } #ifndef _WIN32 - if (addr.getType() == AF_UNIX) { - if (::chmod(ip.c_str(), serverGlobalParams.unixSocketPermissions) == -1) { - error() << "Failed to chmod socket file " << ip << " " - << errnoWithDescription(errno); - fassertFailedNoTrace(40487); - } + if (addr.getType() == AF_UNIX) { + if (::chmod(ip.c_str(), serverGlobalParams.unixSocketPermissions) == -1) { + error() << "Failed to chmod socket file " << ip << " " + << errnoWithDescription(errno); + fassertFailedNoTrace(40487); } -#endif - _acceptors.emplace_back(std::move(acceptor)); } +#endif + _acceptors.emplace_back(std::move(acceptor)); } - if (_acceptors.empty()) { - return Status(ErrorCodes::SocketException, "No available addresses/ports to bind to"); - } + invariant(!_acceptors.empty()); #ifdef MONGO_CONFIG_SSL const auto& sslParams = getSSLGlobalParams(); -- cgit v1.2.1