summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqontinuum <qontinuum@monaco.mc>2022-11-29 21:34:06 +0100
committerqontinuum <qontinuum@monaco.mc>2022-12-11 10:14:18 +0100
commit5852319bd4e26afeabb82b5de5eba7f07552616b (patch)
tree1efe8c587435154bdd8953d0920d5d4a9fd4fcc2
parent67244e684f1664c6e4ff3891a1d606e26a585ad1 (diff)
downloadtor-5852319bd4e26afeabb82b5de5eba7f07552616b.tar.gz
tor-5852319bd4e26afeabb82b5de5eba7f07552616b.zip
Isolate warn_about_resource_exhaution()
-rw-r--r--src/core/mainloop/connection.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index b0b297ac57..7de53e818f 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -1256,6 +1256,23 @@ create_unix_sockaddr(const char *listenaddress, char **readable_address,
}
#endif /* defined(HAVE_SYS_UN_H) || defined(RUNNING_DOXYGEN) */
+/* Log a rate-limited warning about resource exhaustion */
+static void
+warn_about_resource_exhaution(void)
+{
+#define WARN_TOO_MANY_CONNS_INTERVAL (6*60*60)
+ static ratelim_t last_warned = RATELIM_INIT(WARN_TOO_MANY_CONNS_INTERVAL);
+ char *m;
+ if ((m = rate_limit_log(&last_warned, approx_time()))) {
+ int n_conns = get_n_open_sockets();
+ log_warn(LD_NET,"Failing because we have %d connections already. Please "
+ "read doc/TUNING for guidance.%s", n_conns, m);
+ tor_free(m);
+ control_event_general_status(LOG_WARN, "TOO_MANY_CONNECTIONS CURRENT=%d",
+ n_conns);
+ }
+}
+
/**
* A socket failed from resource exhaustion.
*
@@ -1284,17 +1301,7 @@ socket_failed_from_resource_exhaustion(void)
rep_hist_note_overload(OVERLOAD_FD_EXHAUSTED);
}
-#define WARN_TOO_MANY_CONNS_INTERVAL (6*60*60)
- static ratelim_t last_warned = RATELIM_INIT(WARN_TOO_MANY_CONNS_INTERVAL);
- char *m;
- if ((m = rate_limit_log(&last_warned, approx_time()))) {
- int n_conns = get_n_open_sockets();
- log_warn(LD_NET,"Failing because we have %d connections already. Please "
- "read doc/TUNING for guidance.%s", n_conns, m);
- tor_free(m);
- control_event_general_status(LOG_WARN, "TOO_MANY_CONNECTIONS CURRENT=%d",
- n_conns);
- }
+ warn_about_resource_exhaution();
}
#ifdef HAVE_SYS_UN_H