aboutsummaryrefslogtreecommitdiff
path: root/src/core/mainloop/connection.c
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2022-05-21 15:52:31 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2022-05-21 21:30:06 -0400
commit87b2ce6f848ec3a65a7a06ef1edce5a0652ad9a3 (patch)
treef3b4a4e475b0fdfb389e47367dea33b0cfb4777b /src/core/mainloop/connection.c
parent4f038d224f5a3df5fb396eff0173bba0eec89127 (diff)
downloadtor-87b2ce6f848ec3a65a7a06ef1edce5a0652ad9a3.tar.gz
tor-87b2ce6f848ec3a65a7a06ef1edce5a0652ad9a3.zip
Trigger OOS on bind failures (fixes #40597)
Diffstat (limited to 'src/core/mainloop/connection.c')
-rw-r--r--src/core/mainloop/connection.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index 9271a70914..75fc3c8918 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -2224,21 +2224,27 @@ connection_connect_sockaddr,(connection_t *conn,
tor_socket_strerror(errno));
}
- /*
- * We've got the socket open; give the OOS handler a chance to check
- * against configured maximum socket number, but tell it no exhaustion
- * failure.
- */
- connection_check_oos(get_n_open_sockets(), 0);
-
if (bindaddr && bind(s, bindaddr, bindaddr_len) < 0) {
*socket_error = tor_socket_errno(s);
- log_warn(LD_NET,"Error binding network socket: %s",
- tor_socket_strerror(*socket_error));
+ if (ERRNO_IS_EADDRINUSE(*socket_error)) {
+ socket_failed_from_resource_exhaustion();
+ connection_check_oos(get_n_open_sockets(), 1);
+ } else {
+ log_warn(LD_NET,"Error binding network socket: %s",
+ tor_socket_strerror(*socket_error));
+ connection_check_oos(get_n_open_sockets(), 0);
+ }
tor_close_socket(s);
return -1;
}
+ /*
+ * We've got the socket open and bound; give the OOS handler a chance to
+ * check against configured maximum socket number, but tell it no exhaustion
+ * failure.
+ */
+ connection_check_oos(get_n_open_sockets(), 0);
+
tor_assert(options);
if (options->ConstrainedSockets)
set_constrained_socket_buffers(s, (int)options->ConstrainedSockSize);