]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sock: check configured limits at the sock layer, not the listener's
authorWilly Tarreau <w@1wt.eu>
Mon, 11 Apr 2022 13:01:37 +0000 (15:01 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 11 Apr 2022 17:31:47 +0000 (19:31 +0200)
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
src/sock.c

index 1e1a83284077caddc04ae609d965691f1ae5f6e3..b9467e94eb60b0b7f7a853f93b9d2e4dc2c01f49 100644 (file)
@@ -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
index f6ab83f55511c40670c562d1f72a15699b6c1fd0..ae825fc02e58b75120070700ac799268fc0ad317 100644 (file)
@@ -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)