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.
This commit is contained in:
Willy Tarreau 2023-11-17 10:53:36 +01:00
parent f592a0d5dd
commit 662565ddb4

View 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 /* 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 * 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 * 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 && if (srv->curr_idle_conns < srv->low_idle_conns &&
ha_used_fds < global.tune.pool_low_count) 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; goto done;
}
/* Lookup all other threads for an idle connection, starting from last /* Lookup all other threads for an idle connection, starting from last
* unvisited thread, but always staying in the same group. * unvisited thread, but always staying in the same group.