BUG/MINOR: listener: really assign distinct IDs to shards
authorWilly Tarreau <w@1wt.eu>
Wed, 9 Jul 2025 13:52:33 +0000 (15:52 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 1 Oct 2025 13:42:11 +0000 (15:42 +0200)
A fix was made in 3.0 for the case where sharded listeners were using
a same ID with commit 0db8b6034d ("BUG/MINOR: listener: always assign
distinct IDs to shards"). However, the fix is incorrect. By checking the
ID of temporary node instead of the kept one in bind_complete_thread_setup()
it ends up never inserting the used nodes at this point, thus not reserving
them. The side effect is that assigning too close IDs to subsequent
listeners results in the same ID still being assigned twice since not
reserved. Example:

   global
       nbthread 20

   frontend foo
       bind :8000 shards by-thread id 10
       bind :8010 shards by-thread id 20

The first one will start a series from 10 to 29 and the second one a
series from 20 to 39. But 20 not being inserted when creating the shards,
it will remain available for the post-parsing phase that assigns all
unassigned IDs by filling holes, and two listeners will have ID 20.

By checking the correct node, the problem disappears. The patch above
was marked for backporting to 2.6, so this fix should be backported that
far as well.

(cherry picked from commit dd49f1ee6230eaf608f3afa880ef0a6d2b84456e)
Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com>
(cherry picked from commit c12e3b66be1eec8e5ccf6ca25871df77864c2b79)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 68c664f407bbc6d602f832344953e3c132da7217)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/listener.c

index c6566cc..1e59261 100644 (file)
@@ -1836,7 +1836,7 @@ int bind_complete_thread_setup(struct bind_conf *bind_conf, int *err_code)
                                        new_li->luid = new_li->conf.id.key = tmp_li->luid;
                                        tmp_li->luid = 0;
                                        eb32_delete(&tmp_li->conf.id);
-                                       if (tmp_li->luid)
+                                       if (new_li->luid)
                                                eb32_insert(&fe->conf.used_listener_id, &new_li->conf.id);
                                        new_li = tmp_li;
                                }
@@ -1860,7 +1860,7 @@ int bind_complete_thread_setup(struct bind_conf *bind_conf, int *err_code)
                        new_li->luid = new_li->conf.id.key = li->luid;
                        li->luid = 0;
                        eb32_delete(&li->conf.id);
-                       if (li->luid)
+                       if (new_li->luid)
                                eb32_insert(&fe->conf.used_listener_id, &new_li->conf.id);
                }
        }