]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: dns: Stick the TCP nameserver tasks to the resolvers' thread
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 29 Jul 2026 22:26:58 +0000 (00:26 +0200)
committerOlivier Houchard <cognet@ci0.org>
Thu, 30 Jul 2026 11:36:17 +0000 (13:36 +0200)
The tasks handling the TCP nameservers (task_req, task_rsp, task_idle)
are created with no thread affinity, but with thread groups having their
own file descriptors table, it has to run on the same thread as the
one who created the socket, or maybe the other thread will not be able
to use the socket.
In practice, it was not a problem, because the scheduler will wake the
task on the running thread. But that may change in the future, so make
sure we always run on the current thread from start to finish.

src/resolvers.c

index c166ccaa65dbaade7dcdd1f708103c27a777e90f..6a2467564aa6ebb088ab6416f9d716caa95ae037 100644 (file)
@@ -2805,6 +2805,21 @@ static int resolvers_finalize_config(void)
                t->process   = process_resolvers;
                t->context   = resolvers;
                resolvers->t = t;
+
+               /*
+                * Make sure we run those tasks on the same thread that
+                * takes care of those resolvers, as it will create the
+                * socket, and with separate file descriptors tables for
+                * each thread group, we want to make sure we will
+                * run on a thread that can actually use them.
+                */
+               list_for_each_entry(ns, &resolvers->nameservers, list) {
+                       if (ns->stream) {
+                               task_set_thread(ns->stream->task_req, t->tid);
+                               task_set_thread(ns->stream->task_rsp, t->tid);
+                               task_set_thread(ns->stream->task_idle, t->tid);
+                       }
+               }
                task_wakeup(t, TASK_WOKEN_INIT);
        }