]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: quic: add comment on rare thread concurrence during CID alloc
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 24 Nov 2021 14:16:08 +0000 (15:16 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 25 Nov 2021 10:13:12 +0000 (11:13 +0100)
The comment is here to warn about a possible thread concurrence issue
when treating INITIAL packets from the same client. The macro unlikely
is added to further highlight this scarce occurence.

src/xprt_quic.c

index 19c6958d37ee6865ef1731e66c5994341daa4cf4..d36eb468640f3db0209aee9401a717ecca4622ee 100644 (file)
@@ -3771,18 +3771,22 @@ static ssize_t qc_lstnr_pkt_rcv(unsigned char **buf, const unsigned char *end,
                        }
                        HA_RWLOCK_WRUNLOCK(QUIC_LOCK, &l->rx.cids_lock);
 
-                       if (n == &qc->odcid_node) {
+                       /* If the insertion failed, it means that another
+                        * thread has already allocated a QUIC connection for
+                        * the same CID. Liberate our allocated connection.
+                        */
+                       if (unlikely(n != &qc->odcid_node)) {
+                               quic_conn_free(qc);
+                               qc = ebmb_entry(n, struct quic_conn, odcid_node);
+                               pkt->qc = qc;
+                       }
+                       else {
                                /* Enqueue this packet. */
                                pkt->qc = qc;
                                MT_LIST_APPEND(&l->rx.pkts, &pkt->rx_list);
                                /* Try to accept a new connection. */
                                listener_accept(l);
                        }
-                       else {
-                               quic_conn_free(qc);
-                               qc = ebmb_entry(n, struct quic_conn, odcid_node);
-                               pkt->qc = qc;
-                       }
 
                        /* This is the DCID node sent in this packet by the client. */
                        node = &qc->odcid_node;