BUG/MEDIUM: listener: Fix how unlimited number of consecutive accepts is handled
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 30 Apr 2019 10:17:13 +0000 (12:17 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 30 Apr 2019 13:28:29 +0000 (15:28 +0200)
commit102854cbbaa4d22466dddec9035d411db244082f
tree59feecb87581ef721e595a8d15a7cba3e6abc777
parent07425de71777b688e77a9c70a7088c13e66e41e9
BUG/MEDIUM: listener: Fix how unlimited number of consecutive accepts is handled

There is a bug when global.tune.maxaccept is set to -1 (no limit). It is pretty
visible with one process (nbproc sets to 1). The functions listener_accept() and
accept_queue_process() don't expect to handle negative maxaccept values. So
instead of accepting incoming connections without any limit, none are never
accepted and HAProxy loop infinitly in the scheduler.

When there are 2 or more processes, the bug is a bit more subtile. The limit for
a listener is set to 1. So only one connection is accepted at a time by a given
listener. This happens because the listener's maxaccept value is an unsigned
integer. In check_config_validity(), it is first set to UINT_MAX (-1 casted in
an unsigned integer), and then some calculations on it leads to an integer
overflow.

To fix the bug, the listener's maxaccept value is now a signed integer. So, if a
negative value is set for global.tune.maxaccept, we keep it untouched for the
listener and no calculation is made on it. Then, in the listener code, this
signed value is casted to a unsigned one. It simplifies all tests instead of
dealing with negative values. So, it limits the number of connections accepted
at a time to UINT_MAX at most. But, honestly, it not an issue.

This patch must be backported to 1.9 and 1.8.
include/types/listener.h
src/listener.c