From aff4ec86eb4bd51a789cdd22d66f115599fff5fc Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Wed, 24 Nov 2021 15:16:08 +0100 Subject: [PATCH] REORG: quic: add comment on rare thread concurrence during CID alloc 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 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/xprt_quic.c b/src/xprt_quic.c index 19c6958d3..d36eb4686 100644 --- a/src/xprt_quic.c +++ b/src/xprt_quic.c @@ -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;