]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MAJOR: queue: properly keep count of the queue length
authorWilly Tarreau <w@1wt.eu>
Sat, 17 May 2025 08:28:50 +0000 (10:28 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 17 May 2025 08:46:10 +0000 (10:46 +0200)
The queue length was moved to its own variable in commit 583303c48
("MINOR: proxies/servers: Calculate queueslength and use it."), however a
few places were missed in pendconn_unlink() and assign_server_and_queue()
resulting in never decreasing counts on aborted streams. This was
reproduced when injecting more connections than the total backend
could stand in TCP mode and letting some of them time out in the
queue. No backport is needed, this is only 3.2.

src/backend.c
src/queue.c

index 5cfa263115df6119526a5c769fae0bc6896f3551..0c824e668448b68bf74613a53525bf11e35653e4 100644 (file)
@@ -1141,6 +1141,12 @@ int assign_server_and_queue(struct stream *s)
                                        HA_SPIN_UNLOCK(QUEUE_LOCK, &p->queue->lock);
 
                                        _HA_ATOMIC_DEC(&p->queue->length);
+
+                                       if (p->queue->sv)
+                                               _HA_ATOMIC_DEC(&p->queue->sv->queueslength);
+                                       else
+                                               _HA_ATOMIC_DEC(&p->queue->px->queueslength);
+
                                        _HA_ATOMIC_INC(&p->queue->idx);
                                        _HA_ATOMIC_DEC(&s->be->totpend);
 
index d5f737bf5cb2f117db0ae724e8eb10de51284ec7..1f9f6d8ababe5797a497acc0a7d645dcf3e4b684 100644 (file)
@@ -197,10 +197,14 @@ void pendconn_unlink(struct pendconn *p)
 
        if (done) {
                oldidx -= p->queue_idx;
-               if (sv)
+               if (sv) {
                        p->strm->logs.srv_queue_pos += oldidx;
-               else
+                       _HA_ATOMIC_DEC(&sv->queueslength);
+               }
+               else {
                        p->strm->logs.prx_queue_pos += oldidx;
+                       _HA_ATOMIC_DEC(&px->queueslength);
+               }
 
                _HA_ATOMIC_DEC(&q->length);
                _HA_ATOMIC_DEC(&px->totpend);