haproxy/include/common
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
..
accept4.h CLEANUP: build: rename some build macros to use the USE_* ones 2019-05-22 19:47:57 +02:00
base64.h
buf.h MINOR: buf: Add function to insert a string at an absolute offset in a buffer 2020-03-06 14:12:59 +01:00
buffer.h MEDIUM: buffer: remove the buffer_wq lock 2020-02-26 10:39:36 +01:00
cfgparse.h MINOR: cfgparse: make the process/thread parser support a maximum value 2019-01-26 13:25:14 +01:00
chunk.h MINOR: chunk: implement chunk_strncpy() to copy partial strings 2020-02-14 19:02:06 +01:00
compat.h MINOR: debug: use our own backtrace function on clang+x86_64 2020-03-04 12:04:07 +01:00
compiler.h MINOR: compiler: add new alignment macros 2020-02-25 10:34:43 +01:00
config.h MINOR: compiler: move CPU capabilities definition from config.h and complete them 2020-02-21 16:32:57 +01:00
debug.h MINOR: stats/debug: maintain a counter of debug commands issued 2019-10-24 18:38:00 +02:00
defaults.h MEDIUM: cli: Allow multiple filter entries for "show table" 2020-01-22 14:33:17 +01:00
epoll.h CLEANUP: build: rename some build macros to use the USE_* ones 2019-05-22 19:47:57 +02:00
errors.h
fcgi.h MINOR: fcgi: Add function to get the string representation of a record type 2019-10-04 16:12:02 +02:00
h1.h MEDIUM: mux-h1/h1-htx: move HTX convertion of H1 messages in dedicated file 2019-09-17 10:18:54 +02:00
h2.h MINOR: h2: add a function to report H2 error codes as strings 2019-11-25 11:34:26 +01:00
hash.h BUG/MAJOR: hashes: fix the signedness of the hash inputs 2020-01-16 08:23:42 +01:00
hathreads.h MEDIUM: buffer: remove the buffer_wq lock 2020-02-26 10:39:36 +01:00
hpack-dec.h BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00
hpack-enc.h BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00
hpack-huff.h BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00
hpack-tbl.h BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00
http-hdr.h BUILD: use inttypes.h instead of stdint.h 2019-04-01 07:44:56 +02:00
http.h MINOR: http: Add 404 to http-request deny 2020-01-08 16:15:23 +01:00
htx.h MINOR: htx: Add a function to return a block at a specific offset 2020-03-06 14:12:59 +01:00
initcall.h MINOR: initcall: Don't forget to define the __start/stop_init_##stg symbols. 2019-04-10 16:33:25 +02:00
ist.h MINOR: ist: Add struct ist istdup(const struct ist) 2020-03-05 19:53:12 +01:00
istbuf.h Revert "MINOR: istbuf: add b_fromist() to make a buffer from an ist" 2019-10-29 13:09:14 +01:00
memory.h BUG/MAJOR: memory: Don't forget to unlock the rwlock if the pool is empty. 2020-02-03 13:05:31 +01:00
mini-clist.h CLEANUP: mini-clist: simplify nested do { while(1) {} } while (0) 2020-02-11 10:27:04 +01:00
namespace.h CLEANUP: build: rename some build macros to use the USE_* ones 2019-05-22 19:47:57 +02:00
net_helper.h CLEANUP: net_helper: Do not negate the result of unlikely 2020-02-25 07:30:49 +01:00
openssl-compat.h CLEANUP: ssl: remove unused functions in openssl-compat.h 2020-02-14 16:15:00 +01:00
regex.h MEDIUM: regex: modify regex_comp() to atomically allocate/free the my_regex struct 2019-05-07 06:58:15 +02:00
splice.h CLEANUP: build: rename some build macros to use the USE_* ones 2019-05-22 19:47:57 +02:00
standard.h BUG/MEDIUM: random: implement per-thread and per-process random sequences 2020-03-07 06:11:15 +01:00
syscall.h BUILD: enable build on Linux/s390x 2015-10-12 20:58:51 +02:00
template.h
ticks.h
time.h BUILD: remove obsolete support for -mregparm / USE_REGPARM 2020-02-25 07:41:47 +01:00
tools.h BUG/MINOR: ssl: ssl_sock_load_pem_into_ckch is not consistent 2020-01-22 15:55:55 +01:00
uri_auth.h MINOR: stats: replace the ST_* uri_auth flags with STAT_* 2019-10-10 11:30:07 +02:00
version.h MINOR: version: this is development again, update the status 2019-11-25 20:38:32 +01:00
xref.h MEDIUM: xref: Use the new _HA_ATOMIC_* macros. 2019-03-11 17:02:37 +01:00