]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
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)
committerWilly Tarreau <w@1wt.eu>
Wed, 9 Jul 2025 13:52:33 +0000 (15:52 +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.

src/listener.c

index 9d4232e8e594c54e9da35ee476fc0da4f7f09723..f6524d1ba52f7031e17356bb2d194707f8854356 100644 (file)
@@ -1856,7 +1856,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;
                                }
@@ -1880,7 +1880,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);
                }
        }