From e4cae417b0a6639bf4df9123305adc16b764b617 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Mon, 19 Mar 2018 12:47:48 -0700 Subject: [PATCH] enable SO_REUSEPORT option in ipv6 too --- src/core/lib/iomgr/tcp_server_posix.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index 1d9276a5608..631cd07f676 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -61,6 +61,11 @@ static bool has_so_reuseport = false; static void init(void) { #ifndef GPR_MANYLINUX1 int s = socket(AF_INET, SOCK_STREAM, 0); + if (s < 0) { + /* This might be an ipv6-only environment in which case 'socket(AF_INET,..)' + call would fail. Try creating IPv6 socket in that case */ + s = socket(AF_INET6, SOCK_STREAM, 0); + } if (s >= 0) { has_so_reuseport = GRPC_LOG_IF_ERROR("check for SO_REUSEPORT", grpc_set_socket_reuse_port(s, 1));