From c71ef2969b2b055ef166e9fedea306a7bbe2dcba Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Thu, 19 Feb 2026 11:12:47 +0100 Subject: [PATCH] OPTIM: backend: reduce contention when checking MUX init with ALPN In connect_server(), MUX initialization must be delayed if ALPN negotiation is configured, unless ALPN can already be retrieved via the server cache. A readlock is used to consult the server cache. Prior to this patch, it was always taken even if no ALPN is configured. The lock was thus used for every new backend connection instantiation. Rewrite the check so that now the lock is only used if ALPN is configured. Thus, no lock access is done if SSL is not used or if ALPN is not defined. In practice, there will be no performance gain, as the read lock should never block if ALPN is not configured. However, the code is cleaner as it better reflect that only access to server nego_alpn requires the path_params lock protection. --- src/backend.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/backend.c b/src/backend.c index 573bb9ede..109fba3aa 100644 --- a/src/backend.c +++ b/src/backend.c @@ -2070,12 +2070,13 @@ int connect_server(struct stream *s) * to ensure consistency accross the whole stack, in * particular for QUIC between quic-conn and mux layer. */ - HA_RWLOCK_RDLOCK(SERVER_LOCK, &srv->path_params.param_lock); if (IS_HTX_STRM(s) && srv->use_ssl && - (srv->ssl_ctx.alpn_str || srv->ssl_ctx.npn_str) && - srv->path_params.nego_alpn[0] == 0) - may_start_mux_now = 0; - HA_RWLOCK_RDUNLOCK(SERVER_LOCK, &srv->path_params.param_lock); + (srv->ssl_ctx.alpn_str || srv->ssl_ctx.npn_str)) { + HA_RWLOCK_RDLOCK(SERVER_LOCK, &srv->path_params.param_lock); + if (srv->path_params.nego_alpn[0] == 0) + may_start_mux_now = 0; + HA_RWLOCK_RDUNLOCK(SERVER_LOCK, &srv->path_params.param_lock); + } #endif /* TLSEXT_TYPE_application_layer_protocol_negotiation */ #endif /* USE_OPENSSL */