]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: quic: refuse handshakes completed after the listener unbind
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 19 Nov 2026 17:00:34 +0000 (18:00 +0100)
committerOlivier Houchard <cognet@ci0.org>
Thu, 19 Nov 2026 17:27:40 +0000 (18:27 +0100)
QUIC connections are accepted once their handshake is complete. When a
soft-stop unbinds the listener in the meantime, the connection is still
queued, but listener_accept() does not call accept_conn() anymore on the
unbound receiver. The connection never gets its mux and the client waits
until its timeout, while the stopping process keeps it until its idle
timeout and quic_accept_run() wakes itself up in a loop, using 100% of a
thread.

Let's close such connections with a CONNECTION_REFUSED error instead,
when their handshake completes on an unbound listener, or when they are
still queued once it is unbound. The client gets the error right after
its handshake and the stopping process can leave.

This was introduced in 2.8 with the soft-stop support for connections
with their own socket, by commit fb375574f ("MINOR: quic: mark quic-conn
as jobs on socket allocation"). It should be backported to all stable
versions.

This was reported in GitHub issue #3578.

src/quic_sock.c

index 2af4b8f3e8370f53df0f3656851b9d064d9d7dd3..de665d5f87f5b397422c3647d092bae5da327f26 100644 (file)
@@ -1078,6 +1078,16 @@ void qc_want_recv(struct quic_conn *qc)
 /* per-thread accept queues */
 struct quic_accept_queue *quic_accept_queues;
 
+/* Closes <qc> whose handshake is complete but which cannot be accepted
+ * anymore.
+ */
+static void quic_accept_refuse_qc(struct quic_conn *qc)
+{
+       TRACE_STATE("refusing connection on unbound listener", QUIC_EV_CONN_CLOSE, qc);
+       quic_set_connection_close(qc, quic_err_transport(QC_ERR_CONNECTION_REFUSED));
+       tasklet_wakeup(qc->wait_event.tasklet);
+}
+
 /* Install <qc> on the queue ready to be accepted. The queue task is then woken
  * up.
  */
@@ -1091,9 +1101,15 @@ void quic_accept_push_qc(struct quic_conn *qc)
        BUG_ON(qc->flags & QUIC_FL_CONN_ACCEPT_REGISTERED);
 
        BUG_ON(MT_LIST_INLIST(&qc->accept_list));
-       HA_ATOMIC_INC(&l->rx.quic_curr_accept);
-
        qc->flags |= QUIC_FL_CONN_ACCEPT_REGISTERED;
+
+       /* the listener was unbound meanwhile, e.g. by a soft-stop */
+       if (!(l->rx.flags & RX_F_BOUND)) {
+               quic_accept_refuse_qc(qc);
+               return;
+       }
+
+       HA_ATOMIC_INC(&l->rx.quic_curr_accept);
        /* 1. insert the listener in the accept queue
         *
         * Use TRY_APPEND as there is a possible race even with INLIST if
@@ -1120,7 +1136,19 @@ struct task *quic_accept_run(struct task *t, void *ctx, unsigned int i)
        struct quic_accept_queue *queue = &quic_accept_queues[tid];
 
        MT_LIST_FOR_EACH_ENTRY_LOCKED(lthr, &queue->listeners, quic_accept.list, back) {
-               listener_accept(lthr->li);
+               if (!(lthr->li->rx.flags & RX_F_BOUND)) {
+                       struct quic_conn *qc;
+
+                       /* the listener was unbound, nothing can be accepted anymore */
+                       while ((qc = MT_LIST_POP(&lthr->quic_accept.conns, struct quic_conn *, accept_list))) {
+                               BUG_ON(lthr->li->rx.quic_curr_accept <= 0);
+                               HA_ATOMIC_DEC(&lthr->li->rx.quic_curr_accept);
+                               quic_accept_refuse_qc(qc);
+                       }
+               }
+               else
+                       listener_accept(lthr->li);
+
                if (!MT_LIST_ISEMPTY(&lthr->quic_accept.conns)) {
                        /* entry is left in queue */
                        tasklet_wakeup((struct tasklet*)t);