]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: backend: without ->connect(), allow to pick another thread's connection
authorWilly Tarreau <w@1wt.eu>
Fri, 17 Nov 2023 09:53:36 +0000 (10:53 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 17 Nov 2023 17:13:04 +0000 (18:13 +0100)
If less connections than threads are established on a reverse-http gateway
and these servers have a non-nul pool-min-conn, then conn_backend_get()
will refrain from picking available connections from other threads. But
this makes no sense for protocols for which there is no ->connect(),
since there's no way the current thread will manage to establish its own
connection. For such situations we should always accept to use another
thread's connection. That's precisely what this patch does.

src/backend.c

index a90dd905f649d28f224261e345f9ee1b4df22f73..0a256b0703098f9cb9644ddecd2fa6c64e017ed6 100644 (file)
@@ -1204,11 +1204,16 @@ static struct connection *conn_backend_get(struct stream *s, struct server *srv,
        /* Are we allowed to pick from another thread ? We'll still try
         * it if we're running low on FDs as we don't want to create
         * extra conns in this case, otherwise we can give up if we have
-        * too few idle conns.
+        * too few idle conns and the server protocol supports establishing
+        * connections (i.e. not a reverse-http server for example).
         */
        if (srv->curr_idle_conns < srv->low_idle_conns &&
-           ha_used_fds < global.tune.pool_low_count)
-               goto done;
+           ha_used_fds < global.tune.pool_low_count) {
+               const struct protocol *srv_proto = protocol_lookup(srv->addr.ss_family, PROTO_TYPE_STREAM, 0);
+
+               if (srv_proto && srv_proto->connect)
+                       goto done;
+       }
 
        /* Lookup all other threads for an idle connection, starting from last
         * unvisited thread, but always staying in the same group.