diff --git a/gloo/transport/tcp/device.cc b/gloo/transport/tcp/device.cc index 481d67f7d..064ef2851 100644 --- a/gloo/transport/tcp/device.cc +++ b/gloo/transport/tcp/device.cc @@ -101,6 +101,16 @@ static void lookupAddrForHostname(struct attr& attr) { struct addrinfo* rp; for (rp = result; rp != nullptr; rp = rp->ai_next) { auto fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + + // Set SO_REUSEADDR to signal that reuse of the listening port is OK. + printf("in tcp/device.cc"); + int on = 1; + rv = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + if (rv == -1) { + close(fd); + GLOO_ENFORCE_NE(rv, -1); + } + if (fd == -1) { continue; } diff --git a/gloo/transport/tcp/pair.cc b/gloo/transport/tcp/pair.cc index 389d9f2a2..39d01d5c4 100644 --- a/gloo/transport/tcp/pair.cc +++ b/gloo/transport/tcp/pair.cc @@ -162,9 +162,9 @@ void Pair::listen() { signalAndThrowException(GLOO_ERROR_MSG("socket: ", strerror(errno))); } - // Set SO_REUSEADDR to signal that reuse of the listening port is OK. + // Set SO_REUSEPORT to signal that reuse of the listening port is OK. int on = 1; - rv = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + rv = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)); if (rv == -1) { ::close(fd); signalAndThrowException(GLOO_ERROR_MSG("setsockopt: ", strerror(errno)));