]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: threads: unbreak "bind" referencing an incorrect thread number
authorWilly Tarreau <w@1wt.eu>
Fri, 27 Jul 2018 16:07:41 +0000 (18:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 30 Jul 2018 09:10:46 +0000 (11:10 +0200)
The "process" directive on "bind" lines supports process references and
thread references. No check is performed on the thread number validity,
so that if a listener is only bound to non-existent threads, the traffic
will never be processed. It easily happens when setting one bind line per
thread with an incorrect (or reduced) thread count. No warning appears
and some random connections are never served. It also happens when setting
thread references with threads support disabled at build time.

This patch makes use of the all_threads_mask variable to detect if some
referenced threads don't exist, to emit a warning and fix this.

This patch needs to be backported to 1.8, just like the previous one which
it depends on (MINOR: threads: move "nbthread" parsing to hathreads.c).

src/cfgparse.c

index 803a9189bd8531430d5764c183031a491fc0551e..5abe9fa0ca396d3573a99aa8107d1d5947cd1369 100644 (file)
@@ -7581,6 +7581,29 @@ int check_config_validity()
                        } /* HTTP && bufsize < 16384 */
 #endif
 
+                       /* detect and address thread affinity inconsistencies */
+                       nbproc = 0;
+                       if (bind_conf->bind_proc)
+                               nbproc = my_ffsl(bind_conf->bind_proc);
+
+                       mask = bind_conf->bind_thread[nbproc - 1];
+                       if (mask && !(mask & (all_threads_mask ? all_threads_mask : 1UL))) {
+                               unsigned long new_mask = 0;
+
+                               while (mask) {
+                                       new_mask |= mask & (all_threads_mask ? all_threads_mask : 1UL);
+                                       mask >>= global.nbthread;
+                               }
+
+                               for (nbproc = 0; nbproc < LONGBITS; nbproc++) {
+                                       if (!bind_conf->bind_proc || (bind_conf->bind_proc & (1UL << nbproc)))
+                                               bind_conf->bind_thread[nbproc] = new_mask;
+                               }
+                               ha_warning("Proxy '%s': the thread range specified on the 'process' directive of 'bind %s' at [%s:%d] only refers to thread numbers out of the range defined by the global 'nbthread' directive. The thread numbers were remapped to existing threads instead (mask 0x%lx).\n",
+                                          curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line, new_mask);
+                       }
+
+                       /* detect process and nbproc affinity inconsistencies */
                        if (!bind_conf->bind_proc)
                                continue;