]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: fd/threads: fix again incorrect thread selection in wakeup broadcast
authorWilly Tarreau <w@1wt.eu>
Thu, 19 Jan 2023 16:10:10 +0000 (17:10 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jan 2023 18:22:17 +0000 (19:22 +0100)
Commit c1640f79f ("BUG/MEDIUM: fd/threads: fix incorrect thread selection
in wakeup broadcast") fixed an incorrect range being used to pick a thread
when broadcasting a wakeup for a foreign thread, but the selection was still
wrong as the number of threads and their mask was taken from the current
thread instead of the target thread. In addition, the code dealing with the
wakeup of a thread from the same group was still relying on MAX_THREADS
instead of tg->count.

This could theoretically cause random crashes with more than one thread
group though this was never encountered.

This needs to be backported to 2.7.

src/fd.c

index 7f1077cd8cdb1784077b9c9af87b2c93aaae688d..7e56d8a1fe20e270cc6c18e6710ef5e43385497d 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -486,7 +486,8 @@ void updt_fd_polling(const int fd)
 
                fd_add_to_fd_list(&update_list[tgrp - 1], fd);
 
-               thr = one_among_mask(fdtab[fd].thread_mask & tg->threads_enabled, statistical_prng_range(tg->count));
+               thr = one_among_mask(fdtab[fd].thread_mask & ha_tgroup_info[tgrp - 1].threads_enabled,
+                                    statistical_prng_range(ha_tgroup_info[tgrp - 1].count));
                thr += ha_tgroup_info[tgrp - 1].base;
                wake_thread(thr);
 
@@ -515,8 +516,8 @@ void updt_fd_polling(const int fd)
                         * so let's pick a random one so that it doesn't always end up on the same.
                         */
                        int thr = one_among_mask(fdtab[fd].thread_mask & tg->threads_enabled,
-                                                statistical_prng_range(MAX_THREADS));
-                       thr += ha_tgroup_info[tgid - 1].base;
+                                                statistical_prng_range(tg->count));
+                       thr += tg->base;
                        wake_thread(thr);
                }
        }