From: Willy Tarreau Date: Fri, 17 Nov 2023 09:53:36 +0000 (+0100) Subject: MINOR: backend: without ->connect(), allow to pick another thread's connection X-Git-Tag: v2.9-dev10~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=662565ddb492c259cfdaa2d9489a23135a8e93c0;p=thirdparty%2Fhaproxy.git MINOR: backend: without ->connect(), allow to pick another thread's connection 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. --- diff --git a/src/backend.c b/src/backend.c index a90dd905f6..0a256b0703 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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.