haproxy/src
Willy Tarreau 1c306aa84d BUG/MEDIUM: random: implement per-thread and per-process random sequences
As mentioned in previous patch, the random number generator was never
made thread-safe, which used not to be a problem for health checks
spreading, until the uuid sample fetch function appeared. Currently
it is possible for two threads or processes to produce exactly the
same UUID. In fact it's extremely likely that this will happen for
processes, as can be seen with this config:

    global
        nbproc 8

    frontend f
        bind :4445
        mode http
        log stdout daemon format raw
        log-format "%[uuid] %pid"
        redirect location /

It typically produces this log:

  551ce567-0bfb-4bbd-9b58-cdc7e9365325 30645
  551ce567-0bfb-4bbd-9b58-cdc7e9365325 30641
  551ce567-0bfb-4bbd-9b58-cdc7e9365325 30644
  551ce567-0bfb-4bbd-9b58-cdc7e9365325 30639
  551ce567-0bfb-4bbd-9b58-cdc7e9365325 30646
  07764439-c24d-4e6f-a5a6-0138be59e7a8 30645
  07764439-c24d-4e6f-a5a6-0138be59e7a8 30639
  551ce567-0bfb-4bbd-9b58-cdc7e9365325 30643
  07764439-c24d-4e6f-a5a6-0138be59e7a8 30646
  b6773fdd-678f-4d04-96f2-4fb11ad15d6b 30646
  551ce567-0bfb-4bbd-9b58-cdc7e9365325 30642
  07764439-c24d-4e6f-a5a6-0138be59e7a8 30642

What this patch does is to use a distinct per-thread and per-process
seed to make sure the same sequences will not appear, and will then
extend these seeds by "burning" a number of randoms that depends on
the global random seed, the thread ID and the process ID. This adds
roughly 20 extra bits of randomness, resulting in 52 bits total per
thread and per process.

It only takes a few milliseconds to burn these randoms and given
that threads start with a different seed, we know they will not
catch each other. So these random extra bits are essentially added
to ensure randomness between boots and cluster instances.

This replaces all uses of random() with ha_random() which uses the
thread-local state.

This must be backported as far as 2.0 or any version having the
UUID sample-fetch function since it's the main victim here.

It's important to note that this patch, in addition to depending on
the previous one "BUG/MEDIUM: init: initialize the random pool a bit
better", also depends on the preceeding build fixes to address a
circular dependency issue in the include files that prevented it
from building. Part or all of these patches may need to be backported
or adapted as well.
2020-03-07 06:11:15 +01:00
..
51d.c BUG/MEDIUM: random: implement per-thread and per-process random sequences 2020-03-07 06:11:15 +01:00
acl.c MINOR: sample: make sample_parse_expr() able to return an end pointer 2020-02-14 19:02:06 +01:00
action.c MINOR: tcp-rules: Make tcp-request capture a custom action 2020-01-20 15:18:45 +01:00
activity.c CLEANUP: cli: replace all occurrences of manual handling of return messages 2019-08-09 11:26:10 +02:00
applet.c BUG/MEDIUM: applet: always check a fast running applet's activity before killing 2019-10-11 16:05:57 +02:00
arg.c BUG/MINOR: arg: don't reject missing optional args 2020-02-28 16:41:29 +01:00
auth.c BUILD/MINOR: auth: enabling for osx 2019-09-08 12:20:13 +02:00
backend.c BUG/MEDIUM: random: implement per-thread and per-process random sequences 2020-03-07 06:11:15 +01:00
base64.c BUG/MINOR: base64: dec func ignores padding for output size checking 2019-01-14 19:32:15 +01:00
buffer.c MEDIUM: buffer: remove the buffer_wq lock 2020-02-26 10:39:36 +01:00
cache.c MINOR: cache/filters: Initialize the cache filter when stream is created 2020-03-06 15:36:04 +01:00
calltrace.c REORG: trace: rename trace.c to calltrace.c and mention it's not thread-safe 2019-08-22 20:21:00 +02:00
cfgparse-global.c MINOR: config: mark global.debug as deprecated 2020-02-25 11:28:58 +01:00
cfgparse-listen.c MINOR: proxy: Make header_unique_id a struct ist 2020-03-05 19:58:22 +01:00
cfgparse.c BUILD: general: always pass unsigned chars to is* functions 2020-02-25 08:16:33 +01:00
channel.c BUG/MINOR: channel: inject output data at the end of output 2020-01-07 10:51:15 +01:00
checks.c MINOR: checks: do not call conn_xprt_stop_send() anymore 2020-02-21 11:21:12 +01:00
chunk.c BUILD: general: always pass unsigned chars to is* functions 2020-02-25 08:16:33 +01:00
cli.c MINOR: cli: make "show fd" rely on resolve_sym_name() 2020-03-03 18:19:04 +01:00
compression.c MINOR: time: move the cpu, mono, and idle time to thread_info 2019-05-20 21:14:14 +02:00
connection.c CLEANUP: proxy_protocol: Use size_t when parsing TLVs 2020-03-06 11:16:19 +01:00
da.c REORG: proto_htx: Move HTX analyzers & co to http_ana.{c,h} files 2019-07-19 09:24:12 +02:00
debug.c MINOR: debug: add CLI command "debug dev write" to write an arbitrary size 2020-03-05 17:20:15 +01:00
dict.c BUG/MINOR: dict: race condition fix when inserting dictionary entries. 2019-06-11 09:54:12 +02:00
dns.c BUG/MINOR: dns: ignore trailing dot 2020-02-28 10:26:29 +01:00
ev_epoll.c MINOR: epoll: always initialize all of epoll_event to please valgrind 2020-02-26 14:36:27 +01:00
ev_evports.c BUILD: remove obsolete support for -mregparm / USE_REGPARM 2020-02-25 07:41:47 +01:00
ev_kqueue.c BUILD: remove obsolete support for -mregparm / USE_REGPARM 2020-02-25 07:41:47 +01:00
ev_poll.c BUILD: remove obsolete support for -mregparm / USE_REGPARM 2020-02-25 07:41:47 +01:00
ev_select.c BUILD: remove obsolete support for -mregparm / USE_REGPARM 2020-02-25 07:41:47 +01:00
fcgi-app.c CLEANUP: Use isttest() and istfree() 2020-03-05 19:52:07 +01:00
fcgi.c BUILD: general: always pass unsigned chars to is* functions 2020-02-25 08:16:33 +01:00
fd.c CLEANUP: fd: use a union in fd_rm_from_fd_list() to shut aliasing warnings 2020-02-25 09:25:53 +01:00
filters.c BUG/MINOR: filters: Forward everything if no data filters are called 2020-03-06 14:12:59 +01:00
flt_http_comp.c MINOR: compression/filters: Initialize the comp filter when stream is created 2020-03-06 15:36:04 +01:00
flt_spoe.c BUG/MEDIUM: random: implement per-thread and per-process random sequences 2020-03-07 06:11:15 +01:00
flt_trace.c BUG/MEDIUM: random: implement per-thread and per-process random sequences 2020-03-07 06:11:15 +01:00
freq_ctr.c BUG/MAJOR: threads/freq_ctr: use a memory barrier to detect changes 2017-10-31 18:01:18 +01:00
frontend.c MINOR: frontend: switch from conn->addr.{from,to} to conn->{src,dst} 2019-07-19 13:50:09 +02:00
h1.c CLEANUP: http/h1: rely on HA_UNALIGNED_LE instead of checking for CPU families 2020-02-21 16:32:57 +01:00
h1_htx.c MEDIUM: h1-htx: Add HTX EOM block when the message is in H1_MSG_DONE state 2019-12-11 16:46:16 +01:00
h2.c BUG/MINOR: h2: reject again empty :path pseudo-headers 2020-02-26 13:56:24 +01:00
haproxy.c BUG/MEDIUM: random: implement per-thread and per-process random sequences 2020-03-07 06:11:15 +01:00
hash.c BUG/MAJOR: hashes: fix the signedness of the hash inputs 2020-01-16 08:23:42 +01:00
hathreads.c BUILD/MEDIUM: threads: rename thread_info struct to ha_thread_info 2019-10-17 07:15:17 +02:00
hlua.c BUG/MINOR: lua: Init the lua wake_time value before calling a lua function 2020-03-06 14:13:00 +01:00
hlua_fcn.c CLEANUP: lua: fix aliasing issues in the address matching code 2020-02-25 10:24:51 +01:00
hpack-dec.c CLEANUP: Use isttest() and istfree() 2020-03-05 19:52:07 +01:00
hpack-enc.c BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00
hpack-huff.c BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00
hpack-tbl.c BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00
http.c MINOR: ist: Add IST_NULL macro 2020-03-05 19:52:07 +01:00
http_acl.c MEDIUM: init: convert all trivial registration calls to initcalls 2018-11-26 19:50:32 +01:00
http_act.c BUG/MINOR: http-rules: Fix a typo in the reject action function 2020-03-06 15:36:04 +01:00
http_ana.c BUG/MINOR: http-rules: Abort transaction when a redirect is applied on response 2020-03-06 15:44:38 +01:00
http_conv.c MINOR: sample: add us/ms support to date/http_date 2019-10-31 08:47:31 +01:00
http_fetch.c MEDIUM: stream: Make the unique_id member of struct stream a struct ist 2020-03-05 20:21:58 +01:00
http_htx.c CLEANUP: Use isttest() and istfree() 2020-03-05 19:52:07 +01:00
http_rules.c MEDIUM: http: Add a ruleset evaluated on all responses just before forwarding 2020-02-06 14:55:34 +01:00
htx.c MINOR: htx: Use htx_find_offset() to truncate an HTX message 2020-03-06 14:12:59 +01:00
i386-linux-vsys.c MEDIUM: listener: add support for linux's accept4() syscall 2012-10-08 20:11:03 +02:00
lb_chash.c BUG/MEDIUM: lb-chash: Ensure the tree integrity when server weight is increased 2019-08-01 11:35:29 +02:00
lb_fas.c BUG/MEDIUM: lb_fas: Don't test the server's lb_tree from outside the lock 2019-07-05 14:26:15 +02:00
lb_fwlc.c BUG/MINOR: lb/leastconn: ignore the server weights for empty servers 2019-09-06 17:13:44 +02:00
lb_fwrr.c BUG/MAJOR: lb/threads: make sure the avoided server is not full on second pass 2019-05-27 10:29:59 +02:00
lb_map.c MEDIUM: lb/threads: Use the new _HA_ATOMIC_* macros. 2019-03-11 17:02:38 +01:00
listener.c BUG/MEDIUM: listener: only consider running threads when resuming listeners 2020-02-12 10:21:33 +01:00
log.c MEDIUM: stream: Make the unique_id member of struct stream a struct ist 2020-03-05 20:21:58 +01:00
lru.c MINOR: lru: new function to delete <nb> least recently used keys 2016-01-11 07:31:35 +01:00
mailers.c MEDIUM: Add parsing of mailers section 2015-02-03 00:24:16 +01:00
map.c CLEANUP: cli: replace all occurrences of manual handling of return messages 2019-08-09 11:26:10 +02:00
memory.c BUG/MEDIUM: random: implement per-thread and per-process random sequences 2020-03-07 06:11:15 +01:00
mux_fcgi.c BUG/MINOR: connection/debug: do not enforce !event_type on subscribe() anymore 2020-03-05 07:46:33 +01:00
mux_h1.c CLEANUP: Use isttest() and istfree() 2020-03-05 19:52:07 +01:00
mux_h2.c BUG/MINOR: connection/debug: do not enforce !event_type on subscribe() anymore 2020-03-05 07:46:33 +01:00
mux_pt.c MINOR: connection: remove checks for CO_FL_HANDSHAKE before I/O 2020-01-23 17:30:42 +01:00
mworker-prog.c MEDIUM: mworker-prog: Add user/group options to program section 2019-07-15 16:43:16 +02:00
mworker.c BUG/MINOR: mworker: properly pass SIGTTOU/SIGTTIN to workers 2019-12-11 14:26:53 +01:00
namespace.c BUG/MINOR: namespace: avoid closing fd when socket failed in my_socketat 2020-02-14 04:23:08 +01:00
pattern.c BUG/MEDIUM: random: implement per-thread and per-process random sequences 2020-03-07 06:11:15 +01:00
payload.c REORG: proto_htx: Move HTX analyzers & co to http_ana.{c,h} files 2019-07-19 09:24:12 +02:00
peers.c BUG/MEDIUM: random: implement per-thread and per-process random sequences 2020-03-07 06:11:15 +01:00
pipe.c BUG/MEDIUM: pipe/thread: fix atomicity of pipe counters 2020-01-30 09:15:37 +01:00
proto_sockpair.c MINOR: tcp/uxst/sockpair: only ask for I/O when really waiting for a connect() 2020-03-04 19:29:12 +01:00
proto_tcp.c BUG/MINOR: rules: Increment be_counters if backend is assigned for a silent-drop 2020-03-06 15:36:04 +01:00
proto_udp.c BUG/MEDIUM: proto_udp/threads: recv() and send() must not be exclusive. 2019-12-10 19:09:15 +01:00
proto_uxst.c MINOR: tcp/uxst/sockpair: only ask for I/O when really waiting for a connect() 2020-03-04 19:29:12 +01:00
protocol.c BUG/MEDIUM: protocols: add a global lock for the init/deinit stuff 2019-07-24 16:45:02 +02:00
proxy.c MEDIUM: http: Add a ruleset evaluated on all responses just before forwarding 2020-02-06 14:55:34 +01:00
queue.c MINOR: sample: make sample_parse_expr() able to return an end pointer 2020-02-14 19:02:06 +01:00
raw_sock.c MINOR: rawsock: always mark the FD not ready when we're certain it happens 2020-02-28 16:17:09 +01:00
regex.c MEDIUM: regex: modify regex_comp() to atomically allocate/free the my_regex struct 2019-05-07 06:58:15 +02:00
ring.c MINOR: ring: make the parse function automatically set the handler/release 2019-11-15 15:48:12 +01:00
sample.c BUG/MEDIUM: random: implement per-thread and per-process random sequences 2020-03-07 06:11:15 +01:00
server.c BUILD: general: always pass unsigned chars to is* functions 2020-02-25 08:16:33 +01:00
session.c MEDIUM: connection: use CO_FL_WAIT_XPRT more consistently than L4/L6/HANDSHAKE 2020-01-23 16:34:26 +01:00
sha1.c BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00
shctx.c BUG/MEDIUM: shctx: make sure to keep all blocks aligned 2020-02-21 13:45:58 +01:00
signal.c CLEANUP: Fix a typo in the signal subsystem 2018-12-02 18:39:52 +01:00
sink.c MINOR: ring: make the parse function automatically set the handler/release 2019-11-15 15:48:12 +01:00
ssl_sock.c BUG/MINOR: ssl-sock: do not return an uninitialized pointer in ckch_inst_sni_ctx_to_sni_filters 2020-03-05 16:26:12 +01:00
standard.c BUILD: tools: rely on __ELF__ not USE_DL to enable use of dladdr() 2020-03-04 12:04:07 +01:00
stats.c BUILD: general: always pass unsigned chars to is* functions 2020-02-25 08:16:33 +01:00
stick_table.c CLEANUP: stick-tables: use read_u32() to display a node's key 2020-02-25 09:41:22 +01:00
stream.c MEDIUM: stream: Make the unique_id member of struct stream a struct ist 2020-03-05 20:21:58 +01:00
stream_interface.c MEDIUM: connection: remove the intermediary polling state from the connection 2020-02-21 11:21:12 +01:00
task.c MINOR: task: export run_tasks_from_list 2020-03-03 15:26:10 +01:00
tcp_rules.c MINOR: sample: make sample_parse_expr() able to return an end pointer 2020-02-14 19:02:06 +01:00
time.c BUILD: remove obsolete support for -mregparm / USE_REGPARM 2020-02-25 07:41:47 +01:00
trace.c BUG/MEDIUM: trace: fix a typo causing an incorrect startup error 2019-11-25 19:47:22 +01:00
uri_auth.c MINOR: stats: replace the ST_* uri_auth flags with STAT_* 2019-10-10 11:30:07 +02:00
vars.c BUILD: general: always pass unsigned chars to is* functions 2020-02-25 08:16:33 +01:00
version.c MINOR: version: make the version strings variables, not constants 2019-10-16 09:56:57 +02:00
wdt.c MINOR: wdt: do not depend on USE_THREAD 2020-03-04 12:02:27 +01:00
wurfl.c BUG/MINOR: WURFL: fix send_log() function arguments 2019-10-15 10:47:31 +02:00
xprt_handshake.c BUG/MINOR: connection/debug: do not enforce !event_type on subscribe() anymore 2020-03-05 07:46:33 +01:00
xxhash.c BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00