From 9f5431c79fbe51af9445f00bb1a4d67d80e5ada5 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 16 May 2018 17:16:46 +0200 Subject: [PATCH] Comments/explanation for #17873 --- src/core/mainloop/connection.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c index 200ea42433..f1716ed8f0 100644 --- a/src/core/mainloop/connection.c +++ b/src/core/mainloop/connection.c @@ -133,6 +133,22 @@ #include "feature/nodelist/routerinfo_st.h" #include "core/or/socks_request_st.h" +/** + * On Windows and Linux we cannot reliably bind() a socket to an + * address and port if: 1) There's already a socket bound to wildcard + * address (0.0.0.0 or ::) with the same port; 2) We try to bind() + * to wildcard address and there's another socket bound to a + * specific address and the same port. + * + * To address this problem on these two platforms we implement a + * routine that: + * 1) Checks if first attempt to bind() a new socket failed with + * EADDRINUSE. + * 2) If so, it will close the appropriate old listener connection and + * 3) Attempts bind()'ing the new listener socket again. + * + * For further information, see ticket #17873. + */ #if defined(__linux__) || defined(_WIN32) #define ENABLE_LISTENER_REBIND #endif @@ -1191,6 +1207,9 @@ tor_listen(tor_socket_t fd) * * address is only used for logging purposes and to add the information * to the conn. + * + * Set addr_in_use to true in case socket binding fails with + * EADDRINUSE. */ static connection_t * connection_listener_new(const struct sockaddr *listensockaddr,