From 3eadd5b4eb899ff9961568c97312cf5fe10f09b4 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Thu, 5 Feb 2026 10:54:06 +0100 Subject: [PATCH] MINOR: servers: MAke sess_change_server() return the number of requests Change sess_change_server() so that when it decrements the number of requests on the old server, if any, it returns that number to the caller. It will be useful to detect if the server was full, and is not anymore. --- include/haproxy/stream.h | 2 +- src/stream.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/haproxy/stream.h b/include/haproxy/stream.h index 92a57d23d..b25f77c68 100644 --- a/include/haproxy/stream.h +++ b/include/haproxy/stream.h @@ -72,7 +72,7 @@ void strm_dump_to_buffer(struct buffer *buf, const struct stream *strm, const ch struct ist stream_generate_unique_id(struct stream *strm, struct lf_expr *format); void stream_process_counters(struct stream *s); -void sess_change_server(struct stream *strm, struct server *newsrv); +int sess_change_server(struct stream *strm, struct server *newsrv); struct task *process_stream(struct task *t, void *context, unsigned int state); void default_srv_error(struct stream *s, struct stconn *sc); diff --git a/src/stream.c b/src/stream.c index a139f3844..fff757479 100644 --- a/src/stream.c +++ b/src/stream.c @@ -2850,10 +2850,12 @@ void stream_update_time_stats(struct stream *s) * current connection slot. This function also notifies any LB algo which might * expect to be informed about any change in the number of active streams on a * server. + * Returns the number of simultaneous requests on the old server. */ -void sess_change_server(struct stream *strm, struct server *newsrv) +int sess_change_server(struct stream *strm, struct server *newsrv) { struct server *oldsrv = strm->srv_conn; + int count = -1; /* Dynamic servers may be deleted during process lifetime. This * operation is always conducted under thread isolation. Several @@ -2875,8 +2877,8 @@ void sess_change_server(struct stream *strm, struct server *newsrv) * served field has been incremented, so we have to decrement it now. */ if (oldsrv) - _HA_ATOMIC_DEC(&oldsrv->served); - return; + count = _HA_ATOMIC_SUB_FETCH(&oldsrv->served, 1); + return count; } if (oldsrv) { @@ -2891,7 +2893,7 @@ void sess_change_server(struct stream *strm, struct server *newsrv) */ _HA_ATOMIC_DEC(&oldsrv->proxy->served); stream_del_srv_conn(strm); - _HA_ATOMIC_DEC(&oldsrv->served); + count = _HA_ATOMIC_SUB_FETCH(&oldsrv->served, 1); __ha_barrier_atomic_store(); if (oldsrv->proxy->lbprm.server_drop_conn) oldsrv->proxy->lbprm.server_drop_conn(oldsrv); @@ -2904,6 +2906,7 @@ void sess_change_server(struct stream *strm, struct server *newsrv) newsrv->proxy->lbprm.server_take_conn(newsrv); stream_add_srv_conn(strm, newsrv); } + return count; } /* Handle server-side errors for default protocols. It is called whenever a a