]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MAJOR: threads/queue: Fix thread-safety issues on the queues management
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 14 Mar 2018 15:18:06 +0000 (16:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 19 Mar 2018 09:03:06 +0000 (10:03 +0100)
commit5cd4bbd7ab06e341a29a4d2135e80d2e6cf3834a
treeda2964e063716e02ccc38b406a88880153168369
parent510c0d67ef8c44172b63be1a3d69be5f03ef14c3
BUG/MAJOR: threads/queue: Fix thread-safety issues on the queues management

The management of the servers and the proxies queues was not thread-safe at
all. First, the accesses to <strm>->pend_pos were not protected. So it was
possible to release it on a thread (for instance because the stream is released)
and to use it in same time on another one (because we redispatch pending
connections for a server). Then, the accesses to stream's information (flags and
target) from anywhere is forbidden. To be safe, The stream's state must always
be updated in the context of process_stream.

So to fix these issues, the queue module has been refactored. A lock has been
added in the pendconn structure. And now, when we try to dequeue a pending
connection, we start by unlinking it from the server/proxy queue and we wake up
the stream. Then, it is the stream reponsibility to really dequeue it (or
release it). This way, we are sure that only the stream can create and release
its <pend_pos> field.

However, be careful. This new implementation should be thread-safe
(hopefully...). But it is not optimal and in some situations, it could be really
slower in multi-threaded mode than in single-threaded one. The problem is that,
when we try to dequeue pending connections, we process it from the older one to
the newer one independently to the thread's affinity. So we need to wait the
other threads' wakeup to really process them. If threads are blocked in the
poller, this will add a significant latency. This problem happens when maxconn
values are very low.

This patch must be backported in 1.8.
include/common/hathreads.h
include/proto/queue.h
include/types/queue.h
include/types/stream.h
src/proto_http.c
src/queue.c
src/stream.c