Commit 8fd9c637 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook Github Bot

Fix set SO_REUSEPORT error message, save errno, use throwSystemErrorExplicit

Summary:
Fix set SO_REUSEPORT error message, save errno, use throwSystemErrorExplicit

(Note: this ignores all push blocking failures!)

Reviewed By: vitaut

Differential Revision: D20052057

fbshipit-source-id: 2f1b3135ff84242aa7ad38d3063ef9e260c3127c
parent 9037e3ac
...@@ -309,7 +309,7 @@ void AsyncServerSocket::bindSocket( ...@@ -309,7 +309,7 @@ void AsyncServerSocket::bindSocket(
if (!isExistingSocket) { if (!isExistingSocket) {
closeNoInt(fd); closeNoInt(fd);
} }
folly::throwSystemError( folly::throwSystemErrorExplicit(
errnoCopy, errnoCopy,
"failed to bind to async server socket: " + address.describe()); "failed to bind to async server socket: " + address.describe());
} }
...@@ -766,8 +766,10 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) { ...@@ -766,8 +766,10 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) {
int one = 1; int one = 1;
if (netops::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) != if (netops::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) !=
0) { 0) {
auto errnoCopy = errno;
// This isn't a fatal error; just log an error message and continue // This isn't a fatal error; just log an error message and continue
LOG(ERROR) << "failed to set SO_REUSEADDR on async server socket " << errno; LOG(ERROR) << "failed to set SO_REUSEADDR on async server socket "
<< errnoCopy;
} }
// Set reuseport to support multiple accept threads // Set reuseport to support multiple accept threads
...@@ -775,15 +777,19 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) { ...@@ -775,15 +777,19 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) {
if (reusePortEnabled_ && if (reusePortEnabled_ &&
netops::setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(int)) != netops::setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(int)) !=
0) { 0) {
auto errnoCopy = errno;
LOG(ERROR) << "failed to set SO_REUSEPORT on async server socket " LOG(ERROR) << "failed to set SO_REUSEPORT on async server socket "
<< errnoStr(errno); << errnoStr(errnoCopy);
#ifdef WIN32 #ifdef WIN32
folly::throwSystemError(errno, "failed to bind to the async server socket"); folly::throwSystemErrorExplicit(
errnoCopy, "failed to set SO_REUSEPORT on async server socket");
#else #else
SocketAddress address; SocketAddress address;
address.setFromLocalAddress(fd); address.setFromLocalAddress(fd);
folly::throwSystemError( folly::throwSystemErrorExplicit(
errno, "failed to bind to async server socket: " + address.describe()); errnoCopy,
"failed to set SO_REUSEPORT on async server socket: " +
address.describe());
#endif #endif
} }
...@@ -794,14 +800,16 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) { ...@@ -794,14 +800,16 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) {
SO_KEEPALIVE, SO_KEEPALIVE,
(keepAliveEnabled_) ? &one : &zero, (keepAliveEnabled_) ? &one : &zero,
sizeof(int)) != 0) { sizeof(int)) != 0) {
auto errnoCopy = errno;
LOG(ERROR) << "failed to set SO_KEEPALIVE on async server socket: " LOG(ERROR) << "failed to set SO_KEEPALIVE on async server socket: "
<< errnoStr(errno); << errnoStr(errnoCopy);
} }
// Setup FD_CLOEXEC flag // Setup FD_CLOEXEC flag
if (closeOnExec_ && (-1 == netops::set_socket_close_on_exec(fd))) { if (closeOnExec_ && (-1 == netops::set_socket_close_on_exec(fd))) {
auto errnoCopy = errno;
LOG(ERROR) << "failed to set FD_CLOEXEC on async server socket: " LOG(ERROR) << "failed to set FD_CLOEXEC on async server socket: "
<< errnoStr(errno); << errnoStr(errnoCopy);
} }
// Set TCP nodelay if available, MAC OS X Hack // Set TCP nodelay if available, MAC OS X Hack
...@@ -810,9 +818,10 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) { ...@@ -810,9 +818,10 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) {
if (family != AF_UNIX) { if (family != AF_UNIX) {
if (netops::setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) != if (netops::setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) !=
0) { 0) {
auto errnoCopy = errno;
// This isn't a fatal error; just log an error message and continue // This isn't a fatal error; just log an error message and continue
LOG(ERROR) << "failed to set TCP_NODELAY on async server socket: " LOG(ERROR) << "failed to set TCP_NODELAY on async server socket: "
<< errnoStr(errno); << errnoStr(errnoCopy);
} }
} }
#else #else
...@@ -821,9 +830,10 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) { ...@@ -821,9 +830,10 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) {
#if FOLLY_ALLOW_TFO #if FOLLY_ALLOW_TFO
if (tfo_ && detail::tfo_enable(fd, tfoMaxQueueSize_) != 0) { if (tfo_ && detail::tfo_enable(fd, tfoMaxQueueSize_) != 0) {
auto errnoCopy = errno;
// This isn't a fatal error; just log an error message and continue // This isn't a fatal error; just log an error message and continue
LOG(WARNING) << "failed to set TCP_FASTOPEN on async server socket: " LOG(WARNING) << "failed to set TCP_FASTOPEN on async server socket: "
<< folly::errnoStr(errno); << folly::errnoStr(errnoCopy);
} }
#endif #endif
...@@ -832,8 +842,9 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) { ...@@ -832,8 +842,9 @@ void AsyncServerSocket::setupSocket(NetworkSocket fd, int family) {
int ret = int ret =
netops::setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY, &val, sizeof(val)); netops::setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY, &val, sizeof(val));
if (ret) { if (ret) {
auto errnoCopy = errno;
LOG(WARNING) << "failed to set SO_ZEROCOPY on async server socket: " LOG(WARNING) << "failed to set SO_ZEROCOPY on async server socket: "
<< folly::errnoStr(errno); << folly::errnoStr(errnoCopy);
} }
} }
......
...@@ -666,9 +666,11 @@ class AsyncServerSocket : public DelayedDestruction, public AsyncSocketBase { ...@@ -666,9 +666,11 @@ class AsyncServerSocket : public DelayedDestruction, public AsyncSocketBase {
if (netops::setsockopt( if (netops::setsockopt(
handler.socket_, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)) != handler.socket_, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)) !=
0) { 0) {
auto errnoCopy = errno;
LOG(ERROR) << "failed to set SO_REUSEPORT on async server socket " LOG(ERROR) << "failed to set SO_REUSEPORT on async server socket "
<< errno; << errnoCopy;
folly::throwSystemError(errno, "failed to bind to async server socket"); folly::throwSystemErrorExplicit(
errnoCopy, "failed to set SO_REUSEPORT on async server socket");
} }
} }
} }
...@@ -802,10 +804,8 @@ class AsyncServerSocket : public DelayedDestruction, public AsyncSocketBase { ...@@ -802,10 +804,8 @@ class AsyncServerSocket : public DelayedDestruction, public AsyncSocketBase {
class BackoffTimeout; class BackoffTimeout;
virtual void handlerReady( virtual void
uint16_t events, handlerReady(uint16_t events, NetworkSocket fd, sa_family_t family) noexcept;
NetworkSocket fd,
sa_family_t family) noexcept;
NetworkSocket createSocket(int family); NetworkSocket createSocket(int family);
void setupSocket(NetworkSocket fd, int family); void setupSocket(NetworkSocket fd, int family);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment