From e4d09cedb60a3bc8ad92f9cb7d4448fb955a73ed Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 11 Apr 2022 15:01:37 +0200 Subject: [PATCH] MINOR: sock: check configured limits at the sock layer, not the listener's listener_accept() used to continue to enforce the FD limits relative to global.maxsock by itself while it's the last FD-specific test in the whole file. This test has nothing to do there, it ought to be placed in sock_accept_conn() which is the one in charge of FD allocation and tests. Similar tests are already located there by the way. The only tiny difference is that listener_accept() used to pause for one second when this limit was reached, while other similar conditions were pausing only 100ms, so now the same 100ms will apply. But that's not important and could even be considered as an improvement. --- src/listener.c | 10 ---------- src/sock.c | 8 ++++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/listener.c b/src/listener.c index 1e1a832840..b9467e94eb 100644 --- a/src/listener.c +++ b/src/listener.c @@ -965,16 +965,6 @@ void listener_accept(struct listener *l) _HA_ATOMIC_INC(&activity[tid].accepted); - if (unlikely(cli_conn->handle.fd >= global.maxsock)) { - send_log(p, LOG_EMERG, - "Proxy %s reached the configured maximum connection limit. Please check the global 'maxconn' value.\n", - p->id); - close(cli_conn->handle.fd); - conn_free(cli_conn); - expire = tick_add(now_ms, 1000); /* try again in 1 second */ - goto limit_global; - } - /* past this point, l->accept() will automatically decrement * l->nbconn, feconn and actconn once done. Setting next_*conn=0 * allows the error path not to rollback on nbconn. It's more diff --git a/src/sock.c b/src/sock.c index f6ab83f555..ae825fc02e 100644 --- a/src/sock.c +++ b/src/sock.c @@ -103,6 +103,14 @@ struct connection *sock_accept_conn(struct listener *l, int *status) } if (likely(cfd != -1)) { + if (unlikely(cfd >= global.maxsock)) { + close(cfd); + send_log(p, LOG_EMERG, + "Proxy %s reached the configured maximum connection limit. Please check the global 'maxconn' value.\n", + p->id); + goto fail_conn; + } + /* Perfect, the connection was accepted */ conn = conn_new(&l->obj_type); if (!conn) -- 2.39.5