haproxy/include/proto
Willy Tarreau dd0e89a084 BUG/MAJOR: task: add a new TASK_SHARED_WQ flag to fix foreing requeuing
Since 1.9 with commit b20aa9eef3 ("MAJOR: tasks: create per-thread wait
queues") a task bound to a single thread will not use locks when being
queued or dequeued because the wait queue is assumed to be the owner
thread's.

But there exists a rare situation where this is not true: the health
check tasks may be running on one thread waiting for a response, and
may in parallel be requeued by another thread calling health_adjust()
after a detecting a response error in traffic when "observe l7" is set,
and "fastinter" is lower than "inter", requiring to shorten the running
check's timeout. In this case, the task being requeued was present in
another thread's wait queue, thus opening a race during task_unlink_wq(),
and gets requeued into the calling thread's wait queue instead of the
running one's, opening a second race here.

This patch aims at protecting against the risk of calling task_unlink_wq()
from one thread while the task is queued on another thread, hence unlocked,
by introducing a new TASK_SHARED_WQ flag.

This new flag indicates that a task's position in the wait queue may be
adjusted by other threads than then one currently executing it. This means
that such WQ manipulations must be performed under a lock. There are two
types of such tasks:
  - the global ones, using the global wait queue (technically speaking,
    those whose thread_mask has at least 2 bits set).
  - some local ones, which for now will be placed into the global wait
    queue as well in order to benefit from its lock.

The flag is automatically set on initialization if the task's thread mask
indicates more than one thread. The caller must also set it if it intends
to let other threads update the task's expiration delay (e.g. delegated
I/Os), or if it intends to change the task's affinity over time as this
could lead to the same situation.

Right now only the situation described above seems to be affected by this
issue, and it is very difficult to trigger, and even then, will often have
no visible effect beyond stopping the checks for example once the race is
met. On my laptop it is feasible with the following config, chained to
httpterm:

    global
        maxconn 400 # provoke FD errors, calling health_adjust()

    defaults
        mode http
        timeout client 10s
        timeout server 10s
        timeout connect 10s

    listen px
        bind :8001
        option httpchk /?t=50
        server sback 127.0.0.1:8000 backup
        server-template s 0-999 127.0.0.1:8000 check port 8001 inter 100 fastinter 10 observe layer7

This patch will automatically address the case for the checks because
check tasks are created with multiple threads bound and will get the
TASK_SHARED_WQ flag set.

If in the future more tasks need to rely on this (multi-threaded muxes
for example) and the use of the global wait queue becomes a bottleneck
again, then it should not be too difficult to place locks on the local
wait queues and queue the task on its bound thread.

This patch needs to be backported to 2.1, 2.0 and 1.9. It depends on
previous patch "MINOR: task: only check TASK_WOKEN_ANY to decide to
requeue a task".

Many thanks to William Dauchy for providing detailed traces allowing to
spot the problem.
2019-12-19 14:42:22 +01:00
..
acl.h
action.h MINOR: action: new '(http-request|tcp-request content) do-resolve' action 2019-04-23 11:41:52 +02:00
activity.h MINOR: time: move the cpu, mono, and idle time to thread_info 2019-05-20 21:14:14 +02:00
applet.h MINOR: applet: make appctx use their own pool 2019-07-18 10:45:08 +02:00
arg.h
auth.h
backend.h MAJOR: stream: store the target address into s->target_addr 2019-07-19 13:50:09 +02:00
channel.h BUG/MEDIUM: stream-int: Don't rely on CF_WRITE_PARTIAL to unblock opposite si 2019-07-05 14:26:15 +02:00
checks.h
cli.h MINOR: cli: add cli_msg(), cli_err(), cli_dynmsg(), cli_dynerr() 2019-08-09 10:11:38 +02:00
compression.h
connection.h MEDIUM: list: Separate "locked" list from regular list. 2019-09-23 18:16:08 +02:00
dict.h MINOR: dict: Add dictionary new data structure. 2019-06-05 08:33:35 +02:00
dns.h MINOR: action: new '(http-request|tcp-request content) do-resolve' action 2019-04-23 11:41:52 +02:00
fcgi-app.h MEDIUM: fcgi-app: Add FCGI application and filter 2019-09-17 10:18:54 +02:00
fd.h BUG/MEDIUM: fd: HUP is an error only when write is active 2019-10-01 11:52:08 +02:00
filters.h MEDIUM: filters: Adapt filters API to allow again TCP filtering on HTX streams 2019-11-15 13:43:08 +01:00
flt_http_comp.h MINOR: compression: Rename the function check_legacy_http_comp_flt() 2018-12-11 17:09:31 +01:00
freq_ctr.h MINOR: freq_ctr: Make the sliding window sums thread-safe 2019-11-15 13:43:08 +01:00
frontend.h
h1_htx.h MEDIUM: h1-htx: Add HTX EOM block when the message is in H1_MSG_DONE state 2019-12-11 16:46:16 +01:00
hlua_fcn.h
hlua.h MINOR: lua: export applet and task handlers 2019-08-21 14:32:09 +02:00
http_ana.h MINOR: http-ana: Remove the unused function http_reset_txn() 2019-11-07 15:32:52 +01:00
http_fetch.h MEDIUM: http_fetch: Remove code relying on HTTP legacy mode 2019-07-19 09:18:27 +02:00
http_htx.h BUG/MINOR: http_htx: Support empty errorfiles 2019-07-23 14:58:32 +02:00
http_rules.h
lb_chash.h MINOR: lb: allow redispatch when using consistent hash 2019-01-02 20:22:17 +01:00
lb_fas.h
lb_fwlc.h
lb_fwrr.h
lb_map.h
listener.h BUG/MINOR: listener: fix off-by-one in state name check 2019-12-11 15:51:37 +01:00
log.h MINOR: log: Provide a function to emit a log for an application 2019-09-17 10:18:54 +02:00
map.h
mux_pt.h
mworker.h BUG/MINOR: mworker: properly pass SIGTTOU/SIGTTIN to workers 2019-12-11 14:26:53 +01:00
obj_type.h CLEANUP: objtype: make obj_type() and obj_type_name() take consts 2019-05-22 11:50:48 +02:00
pattern.h
payload.h
peers.h MINOR: peers: Make peers protocol support new "server_name" data type. 2019-06-05 08:42:33 +02:00
pipe.h
port_range.h BUG/MEDIUM: port_range: Make the ring buffer lock-free. 2019-04-30 15:10:17 +02:00
proto_sockpair.h
proto_tcp.h MEDIUM: proto: Change the prototype of the connect() method. 2019-05-06 22:12:57 +02:00
proto_udp.h
protocol_buffers.h BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00
protocol.h BUG/MEDIUM: protocols: add a global lock for the init/deinit stuff 2019-07-24 16:45:02 +02:00
proxy.h CLEANUP: proxy: Remove proxy_tbl_by_name 2019-09-30 04:11:36 +02:00
queue.h
raw_sock.h
ring.h MINOR: ring: add a generic CLI io_handler to dump a ring buffer 2019-08-27 17:14:19 +02:00
sample.h MINOR: sample: add us/ms support to date/http_date 2019-10-31 08:47:31 +01:00
server.h MEDIUM: servers: Use LIST_DEL_INIT() instead of LIST_DEL(). 2019-09-23 18:16:08 +02:00
session.h BUG/MEDIUM: sessions: Don't keep an extra idle connection in sessions. 2019-07-04 14:28:18 +02:00
shctx.h BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00
signal.h
sink.h MINOR: sink: now report the number of dropped events on output 2019-08-27 17:14:19 +02:00
spoe.h BUG/MEDIUM: spoe: Be sure the sample is found before setting its context 2019-05-07 22:16:41 +02:00
ssl_sock.h MINOR: ssl: ssl_sock_prepare_ctx() return an error code 2019-11-21 17:48:11 +01:00
stats.h MINOR: stats: prepare to add a description with each stat/info field 2019-10-10 11:30:07 +02:00
stick_table.h MINOR: stick-table: Add "server_name" new data type. 2019-06-05 08:33:35 +02:00
stream_interface.h BUG/MEDIUM: stream_interface: Only use SI_ST_RDY when the mux is ready. 2019-10-29 14:15:20 +01:00
stream.h MEDIUM: stream/trace: Register a new trace source with its events 2019-11-06 10:14:32 +01:00
task.h BUG/MAJOR: task: add a new TASK_SHARED_WQ flag to fix foreing requeuing 2019-12-19 14:42:22 +01:00
tcp_rules.h
template.h
trace.h MINOR: trace: Add a set of macros to trace events if HA is compiled with debug 2019-11-06 10:14:32 +01:00
vars.h