]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
6 years agoBUG/MEDIUM: list: add missing store barriers when updating elements and head
Willy Tarreau [Thu, 28 Feb 2019 10:14:22 +0000 (11:14 +0100)] 
BUG/MEDIUM: list: add missing store barriers when updating elements and head

Commit a8434ec14 ("MINOR: lists: Implement locked variations.")
introduced locked lists which use the elements pointers as locks
for concurrent operations. Under heavy stress the lists occasionally
fail. The cause is a missing barrier at some points when updating
the list element and the head : nothing prevents the compiler (or
CPU) from updating the list head first before updating the element,
making another thread jump to a wrong location. This patch simply
adds the missing barriers before these two opeations.

This will have to be backported if the commit above is backported.

6 years agoBUG/MEDIUM: list: fix LIST_POP_LOCKED's removal of the last pointer
Willy Tarreau [Thu, 28 Feb 2019 14:55:18 +0000 (15:55 +0100)] 
BUG/MEDIUM: list: fix LIST_POP_LOCKED's removal of the last pointer

There was a typo making the last updated pointer be the pre-last element's
prev instead of the last's prev element. It didn't show up during early
tests because the contention is very rare on this one  and it's implicitly
recovered when updating the pointers to go to the next element, but it was
clearly visible in the listener_accept() tests by having all threads block
on LIST_POP_LOCKED() with n==p==LLIST_BUSY.

This will have to be backported if commit a8434ec14 ("MINOR: lists:
Implement locked variations.") is backported.

6 years agoBUG/MEDIUM: list: fix the rollback on addq in the locked liss
Willy Tarreau [Thu, 28 Feb 2019 10:09:56 +0000 (11:09 +0100)] 
BUG/MEDIUM: list: fix the rollback on addq in the locked liss

Commit a8434ec14 ("MINOR: lists: Implement locked variations.")
introduced locked lists which use the elements pointers as locks
for concurrent operations. A copy-paste typo in LIST_ADDQ_LOCKED()
causes corruption in the list in case the next pointer is already
held, as it restores the previous pointer into the next one. It
may impact the server pools.

This will have to be backported if the commit above is backported.

6 years agoBUG/MINOR: config: don't over-count the global maxsock value
Willy Tarreau [Wed, 27 Feb 2019 15:25:28 +0000 (16:25 +0100)] 
BUG/MINOR: config: don't over-count the global maxsock value

global.maxsock used to be augmented by the frontend's maxconn value
for each frontend listener, which is absurd when there are many
listeners in a frontend because the frontend's maxconn fixes an
upper limit to how many connections will be accepted on all of its
listeners anyway. What is needed instead is to add one to count the
listening socket.

In addition, the CLI's and peers' value was incremented twice, the
first time when creating the listener and the second time in the
main init code.

Let's now make sure we only increment global.maxsock by the required
amount of sockets. This means not adding maxconn for each listener,
and relying on the global values when they are correct.

6 years agoDOC: update management.txt to reflect that threads are used by default
Willy Tarreau [Wed, 27 Feb 2019 14:01:46 +0000 (15:01 +0100)] 
DOC: update management.txt to reflect that threads are used by default

It was still mentioned "single-threaded" there. It was also the opportunity
to mention that multiple threads are started by default.

6 years agoMAJOR: threads: enable one thread per CPU by default
Willy Tarreau [Sat, 26 Jan 2019 13:27:06 +0000 (14:27 +0100)] 
MAJOR: threads: enable one thread per CPU by default

Threads have long matured by now, still for most users their usage is
not trivial. It's about time to enable them by default on platforms
where we know the number of CPUs bound. This patch does this, it counts
the number of CPUs the process is bound to upon startup, and enables as
many threads by default. Of course, "nbthread" still overrides this, but
if it's not set the default behaviour is to start one thread per CPU.

The default number of threads is reported in "haproxy -vv". Simply using
"taskset -c" is now enough to adjust this number of threads so that there
is no more need for playing with cpu-map. And thanks to the previous
patches on the listener, the vast majority of configurations will not
need to duplicate "bind" lines with the "process x/y" statement anymore
either, so a simple config will automatically adapt to the number of
processors available.

6 years agoMINOR: config: add global tune.listener.multi-queue setting
Willy Tarreau [Wed, 27 Feb 2019 11:02:18 +0000 (12:02 +0100)] 
MINOR: config: add global tune.listener.multi-queue setting

tune.listener.multi-queue { on | off }
  Enables ('on') or disables ('off') the listener's multi-queue accept which
  spreads the incoming traffic to all threads a "bind" line is allowed to run
  on instead of taking them for itself. This provides a smoother traffic
  distribution and scales much better, especially in environments where threads
  may be unevenly loaded due to external activity (network interrupts colliding
  with one thread for example). This option is enabled by default, but it may
  be forcefully disabled for troubleshooting or for situations where it is
  estimated that the operating system already provides a good enough
  distribution and connections are extremely short-lived.

6 years agoMINOR: activity: add accept queue counters for pushed and overflows
Willy Tarreau [Wed, 27 Feb 2019 09:45:55 +0000 (10:45 +0100)] 
MINOR: activity: add accept queue counters for pushed and overflows

It's important to monitor the accept queues to know if some incoming
connections had to be handled by their originating thread due to an
overflow. It's also important to be able to confirm thread fairness.
This patch adds "accq_pushed" to activity reporting, which reports
the number of connections that were successfully pushed into each
thread's queue, and "accq_full", which indicates the number of
connections that couldn't be pushed because the thread's queue was
full.

6 years agoMAJOR: listener: use the multi-queue for multi-thread listeners
Willy Tarreau [Sun, 27 Jan 2019 14:37:19 +0000 (15:37 +0100)] 
MAJOR: listener: use the multi-queue for multi-thread listeners

The idea is to redistribute an incoming connection to one of the
threads a bind_conf is bound to when there is more than one. We do this
using a random improved by the p2c algorithm : a random() call returns
two different thread numbers. We then compare their respective connection
count and the length of their accept queues, and pick the least loaded
one. We even use this deferred accept mechanism if the target thread
ends up being the local thread, because this maintains fairness between
all connections and tests show that it's about 1% faster this way,
likely due to cache locality. If the target thread's accept queue is
full, the connection is accepted synchronously by the current thread.

6 years agoMINOR: listener: implement multi-queue accept for threads
Willy Tarreau [Sun, 27 Jan 2019 14:37:19 +0000 (15:37 +0100)] 
MINOR: listener: implement multi-queue accept for threads

There is one point where we can migrate a connection to another thread
without taking risk, it's when we accept it : the new FD is not yet in
the fd cache and no task was created yet. It's still possible to assign
it a different thread than the one which accepted the connection. The
only requirement for this is to have one accept queue per thread and
their respective processing tasks that have to be woken up each time
an entry is added to the queue.

This is a multiple-producer, single-consumer model. Entries are added
at the queue's tail and the processing task is woken up. The consumer
picks entries at the head and processes them in order. The accept queue
contains the fd, the source address, and the listener. Each entry of
the accept queue was rounded up to 64 bytes (one cache line) to avoid
cache aliasing because tests have shown that otherwise performance
suffers a lot (5%). A test has shown that it's important to have at
least 256 entries for the rings, as at 128 it's still possible to fill
them often at high loads on small thread counts.

The processing task does almost nothing except calling the listener's
accept() function and updating the global session and SSL rate counters
just like listener_accept() does on synchronous calls.

At this point the accept queue is implemented but not used.

6 years agoMINOR: listener: pre-compute some thread counts per bind_conf
Willy Tarreau [Sun, 3 Feb 2019 10:14:25 +0000 (11:14 +0100)] 
MINOR: listener: pre-compute some thread counts per bind_conf

In order to quickly pick a thread ID when accepting a connection, we'll
need to know certain pre-computed values derived from the thread mask,
which are counts of bits per position multiples of 1, 2, 4, 8, 16 and
32. In practice it is sufficient to compute only the 4 first ones and
store them in the bind_conf. We update the count every time the
bind_thread value is adjusted.

The fields in the bind_conf struct have been moved around a little bit
to make it easier to group all thread bit values into the same cache
line.

The function used to return a thread number is bind_map_thread_id(),
and it maps a number between 0 and 31/63 to a thread ID between 0 and
31/63, starting from the left.

6 years agoMINOR: tools: implement functions to look up the nth bit set in a mask
Willy Tarreau [Tue, 26 Feb 2019 08:56:22 +0000 (09:56 +0100)] 
MINOR: tools: implement functions to look up the nth bit set in a mask

Function mask_find_rank_bit() returns the bit position in mask <m> of
the nth bit set of rank <r>, between 0 and LONGBITS-1 included, starting
from the left. For example ranks 0,1,2,3 for mask 0x55 will be 6, 4, 2
and 0 respectively. This algorithm is based on a popcount variant and
is described here : https://graphics.stanford.edu/~seander/bithacks.html.

6 years agoMINOR: listener: maintain a per-thread count of the number of connections on a listener
Willy Tarreau [Sun, 3 Feb 2019 09:36:29 +0000 (10:36 +0100)] 
MINOR: listener: maintain a per-thread count of the number of connections on a listener

Having this information will help us improve thread-level distribution
of incoming traffic.

6 years agoMAJOR: listener: do not hold the listener lock in listener_accept()
Willy Tarreau [Mon, 25 Feb 2019 18:23:37 +0000 (19:23 +0100)] 
MAJOR: listener: do not hold the listener lock in listener_accept()

This function used to hold the listener's lock as a way to stay safe
against concurrent manipulations, but it turns out this is wrong. First,
the lock is held during l->accept(), which itself might indirectly call
listener_release(), which, if the listener is marked full, could result
in __resume_listener() to be called and the lock being taken twice. In
practice it doesn't happen right now because the listener's FULL state
cannot change while we're doing this.

Second, all the code does is now protected against concurrent accesses.
It used not to be the case in the early days of threads : the frequency
counters are thread-safe. The rate limiting doesn't require extreme
precision. Only the nbconn check is not thread safe.

Third, the parts called here will have to be called from different
threads without holding this lock, and this becomes a bigger issue
if we need to keep this one.

This patch does 3 things which need to be addressed at once :
  1) it moves the lock to the only 2 functions that were not protected
     since called form listener_accept() :
     - limit_listener()
     - listener_full()

  2) it makes sure delete_listener() properly checks its state within
     the lock.

  3) it updates the l->nbconn tracking to make sure that it is always
     properly reported and accounted for. There is a point of particular
     care around the situation where the listener's maxconn is reached
     because the listener has to be marked full before accepting the
     connection, then resumed if the connection finally gets dropped.
     It is not possible to perform this change without removing the
     lock due to the deadlock issue explained above.

This patch almost doubles the accept rate in multi-thread on a shared
port between 8 threads, and multiplies by 4 the connection rate on a
tcp-request connection reject rule.

6 years agoMEDIUM: listener: keep a single thread-mask and warn on "process" misuse
Willy Tarreau [Sat, 2 Feb 2019 12:14:34 +0000 (13:14 +0100)] 
MEDIUM: listener: keep a single thread-mask and warn on "process" misuse

Now that nbproc and nbthread are exclusive, we can still provide more
detailed explanations about what we've found in the config when a bind
line appears on multiple threads and processes at the same time, then
ignore the setting.

This patch reduces the listener's thread mask to a single mask instead
of an array of masks per process. Now we have only one thread mask and
one process mask per bind-conf. This removes ~504 bytes of RAM per
bind-conf and will simplify handling of thread masks.

If a "bind" line only refers to process numbers not found by its parent
frontend or not covered by the global nbproc directive, or to a thread
not covered by the global nbthread directive, a warning is emitted saying
what will be used instead.

6 years agoMAJOR: config: disable support for nbproc and nbthread in parallel
Willy Tarreau [Sat, 2 Feb 2019 11:56:15 +0000 (12:56 +0100)] 
MAJOR: config: disable support for nbproc and nbthread in parallel

When 1.8 was released, we wanted to support both nbthread and nbproc to
observe how things would go. Since then it appeared obvious that the two
are never used together because of the pain to configure affinity in this
case, and instead of bringing benefits, it brings the limitations of both
models, and causes multiple threads to compete for the same CPU. In
addition, it costs a lot to support both in parallel, so let's get rid
of this once for all.

6 years agoDOC: fix alphabetic ordering for "tune.fail-alloc" setting
Willy Tarreau [Wed, 27 Feb 2019 10:35:12 +0000 (11:35 +0100)] 
DOC: fix alphabetic ordering for "tune.fail-alloc" setting

Last time I verified, the "f" letter was not between the "l" and the
"m", but between the "e" and the "g", so let's move this entry to the
right place.

6 years agoBUG/MINOR: listener: keep accept rate counters accurate under saturation
Willy Tarreau [Mon, 25 Feb 2019 14:02:04 +0000 (15:02 +0100)] 
BUG/MINOR: listener: keep accept rate counters accurate under saturation

The test on l->nbconn forces to exit the loop before updating the freq
counters, so the last session which reaches a listener's limit will not
be accounted for in the session rate measurement.

Let's move the test at the beginning of the loop and mark the listener
as saturated on exit.

This may be backported to 1.9 and 1.8.

6 years agoBUG/MEDIUM: standard: Wrong reallocation size.
Frédéric Lécaille [Tue, 26 Feb 2019 17:19:48 +0000 (18:19 +0100)] 
BUG/MEDIUM: standard: Wrong reallocation size.

The number of bytes to use with "my_realloc2()" in parse_dotted_nums()
was wrong: missing multiplication by the size of an element of an array
when reallocating it.

6 years agoMINOR: cfgparse: Add a cast to make gcc happier.
Olivier Houchard [Tue, 26 Feb 2019 17:48:01 +0000 (18:48 +0100)] 
MINOR: cfgparse: Add a cast to make gcc happier.

When calling calloc(), cast global.nbthread to unsigned int, so that gcc
doesn't freak out, as it has no way of knowing global.nbthread can't be
negative.

6 years agoBUG/MEDIUM: lists: Properly handle the case we're removing the first elt.
Olivier Houchard [Tue, 26 Feb 2019 17:46:07 +0000 (18:46 +0100)] 
BUG/MEDIUM: lists: Properly handle the case we're removing the first elt.

In LIST_DEL_LOCKED(), initialize p2 to NULL, and only attempt to set it back
to its previous value if we had a previous element, and thus p2 is non-NULL.

6 years agoMEDIUM: servers: Reorganize the way idle connections are cleaned.
Olivier Houchard [Thu, 14 Feb 2019 17:29:09 +0000 (18:29 +0100)] 
MEDIUM: servers: Reorganize the way idle connections are cleaned.

Instead of having one task per thread and per server that does clean the
idling connections, have only one global task for every servers.
That tasks parses all the servers that currently have idling connections,
and remove half of them, to put them in a per-thread list of connections
to kill. For each thread that does have connections to kill, wake a task
to do so, so that the cleaning will be done in the context of said thread.

6 years agoMEDIUM: servers: Used a locked list for idle_orphan_conns.
Olivier Houchard [Tue, 22 Jan 2019 15:11:03 +0000 (16:11 +0100)] 
MEDIUM: servers: Used a locked list for idle_orphan_conns.

Use the locked macros when manipulating idle_orphan_conns, so that other
threads can remove elements from it.
It will be useful later to avoid having a task per server and per thread to
cleanup the orphan list.

6 years agoMINOR: lists: Implement locked variations.
Olivier Houchard [Fri, 18 Jan 2019 16:26:26 +0000 (17:26 +0100)] 
MINOR: lists: Implement locked variations.

Implement LIST_ADD_LOCKED(), LIST_ADDQ_LOCKED(), LIST_DEL_LOCKED() and
LIST_POP_LOCKED().

LIST_ADD_LOCKED, LIST_ADDQ_LOCKED and LIST_DEL_LOCKED work the same as
LIST_ADD, LIST_ADDQ and LIST_DEL, except before any manipulation it locks
the relevant elements of the list, so it's safe to manipulate the list
with multiple threads.
LIST_POP_LOCKED() removes the first element from the list, and returns its
data.

6 years agoCLEANUP: stream: Remove bogus loop in conn_si_send_proxy
Tim Duesterhus [Tue, 26 Feb 2019 16:09:51 +0000 (17:09 +0100)] 
CLEANUP: stream: Remove bogus loop in conn_si_send_proxy

The if-statement was converted into a while-loop in
7fe45698f58a53dda9182a5970a2ea4bda9f92fe to handle EINTR.

This special handling was later replaced in
0a03c0f022faf2773995fc8b9d14256c8a306e5a by conn_sock_send.

The while-loop was not changed back and is not unconditionally
exited after one iteration, with no `continue` inside the body.

Replace by an if-statement.

6 years agoCLEANUP: http: Remove unreachable code in parse_http_req_capture
Tim Duesterhus [Tue, 26 Feb 2019 16:09:50 +0000 (17:09 +0100)] 
CLEANUP: http: Remove unreachable code in parse_http_req_capture

`len` has already been checked to be strictly positive a few lines above.

This unreachable code was introduced in 82bf70dff4eff42397fecfcb9e97a0a7ce721c49.

6 years ago[RELEASE] Released version 2.0-dev1 v2.0-dev1
Willy Tarreau [Tue, 26 Feb 2019 15:43:49 +0000 (16:43 +0100)] 
[RELEASE] Released version 2.0-dev1

Released version 2.0-dev1 with the following main changes :
    - MINOR: mux-h2: only increase the connection window with the first update
    - REGTESTS: remove the expected window updates from H2 handshakes
    - BUG/MINOR: mux-h2: make empty HEADERS frame return a connection error
    - BUG/MEDIUM: mux-h2: mark that we have too many CS once we have more than the max
    - MEDIUM: mux-h2: remove padlen during headers phase
    - MINOR: h2: add a bit-based frame type representation
    - MINOR: mux-h2: remove useless check for empty frame length in h2s_decode_headers()
    - MEDIUM: mux-h2: decode HEADERS frames before allocating the stream
    - MINOR: mux-h2: make h2c_send_rst_stream() use the dummy stream's error code
    - MINOR: mux-h2: add a new dummy stream for the REFUSED_STREAM error code
    - MINOR: mux-h2: fail stream creation more cleanly using RST_STREAM
    - MINOR: buffers: add a new b_move() function
    - MINOR: mux-h2: make h2_peek_frame_hdr() support an offset
    - MEDIUM: mux-h2: handle decoding of CONTINUATION frames
    - CLEANUP: mux-h2: remove misleading comments about CONTINUATION
    - BUG/MEDIUM: servers: Don't try to reuse connection if we switched server.
    - BUG/MEDIUM: tasks: Decrement tasks_run_queue in tasklet_free().
    - BUG/MINOR: htx: send the proper authenticate header when using http-request auth
    - BUG/MEDIUM: mux_h2: Don't add to the idle list if we're full.
    - BUG/MEDIUM: servers: Fail if we fail to allocate a conn_stream.
    - BUG/MAJOR: servers: Use the list api correctly to avoid crashes.
    - BUG/MAJOR: servers: Correctly use LIST_ELEM().
    - BUG/MAJOR: sessions: Use an unlimited number of servers for the conn list.
    - BUG/MEDIUM: servers: Flag the stream_interface on handshake error.
    - MEDIUM: servers: Be smarter when switching connections.
    - MEDIUM: sessions: Keep track of which connections are idle.
    - MINOR: payload: add sample fetch for TLS ALPN
    - BUG/MEDIUM: log: don't mark log FDs as non-blocking on terminals
    - MINOR: channel: Add the function channel_add_input
    - MINOR: stats/htx: Call channel_add_input instead of updating channel state by hand
    - BUG/MEDIUM: cache: Be sure to end the forwarding when XFER length is unknown
    - BUG/MAJOR: htx: Return the good block address after a defrag
    - MINOR: lb: allow redispatch when using consistent hash
    - CLEANUP: mux-h2: fix end-of-stream flag name when processing headers
    - BUG/MEDIUM: mux-h2: always restart reading if data are available
    - BUG/MINOR: mux-h2: set the stream-full flag when leaving h2c_decode_headers()
    - BUG/MINOR: mux-h2: don't check the CS count in h2c_bck_handle_headers()
    - BUG/MINOR: mux-h2: mark end-of-stream after processing response HEADERS, not before
    - BUG/MINOR: mux-h2: only update rxbuf's length for H1 headers
    - BUG/MEDIUM: mux-h1: use per-direction flags to indicate transitions
    - BUG/MEDIUM: mux-h1: make HTX chunking consistent with H2
    - BUG/MAJOR: stream-int: Update the stream expiration date in stream_int_notify()
    - BUG/MEDIUM: proto-htx: Set SI_FL_NOHALF on server side when request is done
    - BUG/MEDIUM: mux-h1: Add a task to handle connection timeouts
    - MINOR: mux-h2: make h2c_decode_headers() return a status, not a count
    - MINOR: mux-h2: add a new dummy stream : h2_error_stream
    - MEDIUM: mux-h2: make h2c_decode_headers() support recoverable errors
    - BUG/MINOR: mux-h2: detect when the HTX EOM block cannot be added after headers
    - MINOR: mux-h2: remove a misleading and impossible test
    - CLEANUP: mux-h2: clean the stream error path on HEADERS frame processing
    - MINOR: mux-h2: check for too many streams only for idle streams
    - MINOR: mux-h2: set H2_SF_HEADERS_RCVD when a HEADERS frame was decoded
    - BUG/MEDIUM: mux-h2: decode trailers in HEADERS frames
    - MINOR: h2: add h2_make_h1_trailers to turn H2 headers to H1 trailers
    - MEDIUM: mux-h2: pass trailers to H1 (legacy mode)
    - MINOR: htx: add a new function to add a block without filling it
    - MINOR: h2: add h2_make_htx_trailers to turn H2 headers to HTX trailers
    - MEDIUM: mux-h2: pass trailers to HTX
    - MINOR: mux-h1: parse the content-length header on output and set H1_MF_CLEN
    - BUG/MEDIUM: mux-h1: don't enforce chunked encoding on requests
    - MINOR: mux-h2: make HTX_BLK_EOM processing idempotent
    - MINOR: h1: make the H1 headers block parser able to parse headers only
    - MEDIUM: mux-h2: emit HEADERS frames when facing HTX trailers blocks
    - MINOR: stream/htx: Add info about the HTX structs in "show sess all" command
    - MINOR: stream: Add the subscription events of SIs in "show sess all" command
    - MINOR: mux-h1: Add the subscription events in "show fd" command
    - BUG/MEDIUM: h1: Get the h1m state when restarting the headers parsing
    - BUG/MINOR: cache/htx: Be sure to count partial trailers
    - BUG/MEDIUM: h1: In h1_init(), wake the tasklet instead of calling h1_recv().
    - BUG/MEDIUM: server: Defer the mux init until after xprt has been initialized.
    - MINOR: connections: Remove a stall comment.
    - BUG/MEDIUM: cli: make "show sess" really thread-safe
    - BUILD: add a new file "version.c" to carry version updates
    - MINOR: stream/htx: add the HTX flags output in "show sess all"
    - MINOR: stream/cli: fix the location of the waiting flag in "show sess all"
    - MINOR: stream/cli: report more info about the HTTP messages on "show sess all"
    - BUG/MINOR: lua: bad args are returned for Lua actions
    - BUG/MEDIUM: lua: dead lock when Lua tasks are trigerred
    - MINOR: htx: Add an helper function to get the max space usable for a block
    - MINOR: channel/htx: Add HTX version for some helper functions
    - BUG/MEDIUM: cache/htx: Respect the reserve when cached objects are served
    - BUG/MINOR: stats/htx: Respect the reserve when the stats page is dumped
    - DOC: regtest: make it clearer what the purpose of the "broken" series is
    - REGTEST: mailers: add new test for 'mailers' section
    - REGTEST: Add a reg test for health-checks over SSL/TLS.
    - BUG/MINOR: mux-h1: Close connection on shutr only when shutw was really done
    - MEDIUM: mux-h1: Clarify how shutr/shutw are handled
    - BUG/MINOR: compression: Disable it if another one is already in progress
    - BUG/MINOR: filters: Detect cache+compression config on legacy HTTP streams
    - BUG/MINOR: cache: Disable the cache if any compression filter precedes it
    - REGTEST: Add some informatoin to test results.
    - MINOR: htx: Add a function to truncate all blocks after a specific offset
    - MINOR: channel/htx: Add the HTX version of channel_truncate/erase
    - BUG/MINOR: proto_htx: Use HTX versions to truncate or erase a buffer
    - BUG/CRITICAL: mux-h2: re-check the frame length when PRIORITY is used
    - DOC: Fix typo in req.ssl_alpn example (commit 4afdd138424ab...)
    - DOC: http-request cache-use / http-response cache-store expects cache name
    - REGTEST: "capture (request|response)" regtest.
    - BUG/MINOR: lua/htx: Respect the reserve when data are send from an HTX applet
    - REGTEST: filters: add compression test
    - BUG/MEDIUM: init: Initialize idle_orphan_conns for first server in server-template
    - BUG/MEDIUM: ssl: Disable anti-replay protection and set max data with 0RTT.
    - DOC: Be a bit more explicit about allow-0rtt security implications.
    - MINOR: mux-h1: make the mux_h1_ops struct static
    - BUILD: makefile: add an EXTRA_OBJS variable to help build optional code
    - BUG/MEDIUM: connection: properly unregister the mux on failed initialization
    - BUG/MAJOR: cache: fix confusion between zero and uninitialized cache key
    - REGTESTS: test case for map_regm commit 271022150d
    - REGTESTS: Basic tests for concat,strcmp,word,field,ipmask converters
    - REGTESTS: Basic tests for using maps to redirect requests / select backend
    - DOC: REGTESTS README varnishtest -Dno-htx= define.
    - MINOR: spoe: Make the SPOE filter compatible with HTX proxies
    - MINOR: checks: Store the proxy in checks.
    - BUG/MEDIUM: checks: Avoid having an associated server for email checks.
    - REGTEST: Switch to vtest.
    - REGTEST: Adapt reg test doc files to vtest.
    - BUG/MEDIUM: h1: Make sure we destroy an inactive connectin that did shutw.
    - BUG/MINOR: base64: dec func ignores padding for output size checking
    - BUG/MEDIUM: ssl: missing allocation failure checks loading tls key file
    - MINOR: ssl: add support of aes256 bits ticket keys on file and cli.
    - BUG/MINOR: backend: don't use url_param_name as a hint for BE_LB_ALGO_PH
    - BUG/MINOR: backend: balance uri specific options were lost across defaults
    - BUG/MINOR: backend: BE_LB_LKUP_CHTREE is a value, not a bit
    - MINOR: backend: move url_param_name/len to lbprm.arg_str/len
    - MINOR: backend: make headers and RDP cookie also use arg_str/len
    - MINOR: backend: add new fields in lbprm to store more LB options
    - MINOR: backend: make the header hash use arg_opt1 for use_domain_only
    - MINOR: backend: remap the balance uri settings to lbprm.arg_opt{1,2,3}
    - MINOR: backend: move hash_balance_factor out of chash
    - MEDIUM: backend: move all LB algo parameters into an union
    - MINOR: backend: make the random algorithm support a number of draws
    - BUILD/MEDIUM: da: Necessary code changes for new buffer API.
    - BUG/MINOR: stick_table: Prevent conn_cur from underflowing
    - BUG: 51d: Changes to the buffer API in 1.9 were not applied to the 51Degrees code.
    - BUG/MEDIUM: stats: Get the right scope pointer depending on HTX is used or not
    - DOC: add a missing space in the documentation for bc_http_major
    - REGTEST: checks basic stats webpage functionality
    - BUG/MEDIUM: servers: Make assign_tproxy_address work when ALPN is set.
    - BUG/MEDIUM: connections: Add the CO_FL_CONNECTED flag if a send succeeded.
    - DOC: add github issue templates
    - MINOR: cfgparse: Extract some code to be re-used.
    - CLEANUP: cfgparse: Return asap from cfg_parse_peers().
    - CLEANUP: cfgparse: Code reindentation.
    - MINOR: cfgparse: Useless frontend initialization in "peers" sections.
    - MINOR: cfgparse: Rework peers frontend init.
    - MINOR: cfgparse: Simplication.
    - MINOR: cfgparse: Make "peer" lines be parsed as "server" lines.
    - MINOR: peers: Make outgoing connection to SSL/TLS peers work.
    - MINOR: cfgparse: SSL/TLS binding in "peers" sections.
    - DOC: peers: SSL/TLS documentation for "peers"
    - BUG/MINOR: startup: certain goto paths in init_pollers fail to free
    - BUG/MEDIUM: checks: fix recent regression on agent-check making it crash
    - BUG/MINOR: server: don't always trust srv_check_health when loading a server state
    - BUG/MINOR: check: Wake the check task if the check is finished in wake_srv_chk()
    - BUG/MEDIUM: ssl: Fix handling of TLS 1.3 KeyUpdate messages
    - DOC: mention the effect of nf_conntrack_tcp_loose on src/dst
    - BUG/MINOR: proto-htx: Return an error if all headers cannot be received at once
    - BUG/MEDIUM: mux-h2/htx: Respect the channel's reserve
    - BUG/MINOR: mux-h1: Apply the reserve on the channel's buffer only
    - BUG/MINOR: mux-h1: avoid copying output over itself in zero-copy
    - BUG/MAJOR: mux-h2: don't destroy the stream on failed allocation in h2_snd_buf()
    - BUG/MEDIUM: backend: also remove from idle list muxes that have no more room
    - BUG/MEDIUM: mux-h2: properly abort on trailers decoding errors
    - MINOR: h2: declare new sets of frame types
    - BUG/MINOR: mux-h2: CONTINUATION in closed state must always return GOAWAY
    - BUG/MINOR: mux-h2: headers-type frames in HREM are always a connection error
    - BUG/MINOR: mux-h2: make it possible to set the error code on an already closed stream
    - BUG/MINOR: hpack: return a compression error on invalid table size updates
    - MINOR: server: make sure pool-max-conn is >= -1
    - BUG/MINOR: stream: take care of synchronous errors when trying to send
    - CLEANUP: server: fix indentation mess on idle connections
    - BUG/MINOR: mux-h2: always check the stream ID limit in h2_avail_streams()
    - BUG/MINOR: mux-h2: refuse to allocate a stream with too high an ID
    - BUG/MEDIUM: backend: never try to attach to a mux having no more stream available
    - MINOR: server: add a max-reuse parameter
    - MINOR: mux-h2: always consider a server's max-reuse parameter
    - MEDIUM: stream-int: always mark pending outgoing SI_ST_CON
    - MINOR: stream: don't wait before retrying after a failed connection reuse
    - MEDIUM: h2: always parse and deduplicate the content-length header
    - BUG/MINOR: mux-h2: always compare content-length to the sum of DATA frames
    - CLEANUP: h2: Remove debug printf in mux_h2.c
    - MINOR: cfgparse: make the process/thread parser support a maximum value
    - MINOR: threads: make MAX_THREADS configurable at build time
    - DOC: nbthread is no longer experimental.
    - BUG/MINOR: listener: always fill the source address for accepted socketpairs
    - BUG/MINOR: mux-h2: do not report available outgoing streams after GOAWAY
    - BUG/MINOR: spoe: corrected fragmentation string size
    - BUG/MINOR: task: fix possibly missed event in inter-thread wakeups
    - BUG/MEDIUM: servers: Attempt to reuse an unfinished connection on retry.
    - BUG/MEDIUM: backend: always call si_detach_endpoint() on async connection failure
    - SCRIPTS: add the issue tracker URL to the announce script
    - MINOR: peers: Extract some code to be reused.
    - CLEANUP: peers: Indentation fixes.
    - MINOR: peers: send code factorization.
    - MINOR: peers: Add new functions to send code and reduce the I/O handler.
    - MEDIUM: peers: synchronizaiton code factorization to reduce the size of the I/O handler.
    - MINOR: peers: Move update receive code to reduce the size of the I/O handler.
    - MINOR: peers: Move ack, switch and definition receive code to reduce the size of the I/O handler.
    - MINOR: peers: Move high level receive code to reduce the size of I/O handler.
    - CLEANUP: peers: Be more generic.
    - MINOR: peers: move error handling to reduce the size of the I/O handler.
    - MINOR: peers: move messages treatment code to reduce the size of the I/O handler.
    - MINOR: peers: move send code to reduce the size of the I/O handler.
    - CLEANUP: peers: Remove useless statements.
    - MINOR: peers: move "hello" message treatment code to reduce the size of the I/O handler.
    - MINOR: peers: move peer initializations code to reduce the size of the I/O handler.
    - CLEANUP: peers: factor the error handling code in peer_treet_updatemsg()
    - CLEANUP: peers: factor error handling in peer_treat_definedmsg()
    - BUILD/MINOR: peers: shut up a build warning introduced during last cleanup
    - BUG/MEDIUM: mux-h2: only close connection on request frames on closed streams
    - CLEANUP: mux-h2: remove two useless but misleading assignments
    - BUG/MEDIUM: checks: Check that conn_install_mux succeeded.
    - BUG/MEDIUM: servers: Only destroy a conn_stream we just allocated.
    - BUG/MEDIUM: servers: Don't add an incomplete conn to the server idle list.
    - BUG/MEDIUM: checks: Don't try to set ALPN if connection failed.
    - BUG/MEDIUM: h2: In h2_send(), stop the loop if we failed to alloc a buf.
    - BUG/MEDIUM: peers: Handle mux creation failure.
    - BUG/MEDIUM: servers: Close the connection if we failed to install the mux.
    - BUG/MEDIUM: compression: Rewrite strong ETags
    - BUG/MINOR: deinit: tcp_rep.inspect_rules not deinit, add to deinit
    - CLEANUP: mux-h2: remove misleading leftover test on h2s' nullity
    - BUG/MEDIUM: mux-h2: wake up flow-controlled streams on initial window update
    - BUG/MEDIUM: mux-h2: fix two half-closed to closed transitions
    - BUG/MEDIUM: mux-h2: make sure never to send GOAWAY on too old streams
    - BUG/MEDIUM: mux-h2: do not abort HEADERS frame before decoding them
    - BUG/MINOR: mux-h2: make sure response HEADERS are not received in other states than OPEN and HLOC
    - MINOR: h2: add a generic frame checker
    - MEDIUM: mux-h2: check the frame validity before considering the stream state
    - CLEANUP: mux-h2: remove stream ID and frame length checks from the frame parsers
    - BUG/MINOR: mux-h2: make sure request trailers on aborted streams don't break the connection
    - DOC: compression: Update the reasons for disabled compression
    - BUG/MEDIUM: buffer: Make sure b_is_null handles buffers waiting for allocation.
    - DOC: htx: make it clear that htxbuf() and htx_from_buf() always return valid pointers
    - MINOR: htx: never check for null htx pointer in htx_is_{,not_}empty()
    - MINOR: mux-h2: consistently rely on the htx variable to detect the mode
    - BUG/MEDIUM: peers: Peer addresses parsing broken.
    - BUG/MEDIUM: mux-h1: Don't add "transfer-encoding" if message-body is forbidden
    - BUG/MEDIUM: connections: Don't forget to remove CO_FL_SESS_IDLE.
    - BUG/MINOR: stream: don't close the front connection when facing a backend error
    - BUG/MEDIUM: mux-h2: wait for the mux buffer to be empty before closing the connection
    - MINOR: stream-int: add a new flag to mention that we want the connection to be killed
    - MINOR: connstream: have a new flag CS_FL_KILL_CONN to kill a connection
    - BUG/MEDIUM: mux-h2: do not close the connection on aborted streams
    - BUG/MINOR: server: fix logic flaw in idle connection list management
    - MINOR: mux-h2: max-concurrent-streams should be unsigned
    - MINOR: mux-h2: make sure to only check concurrency limit on the frontend
    - MINOR: mux-h2: learn and store the peer's advertised MAX_CONCURRENT_STREAMS setting
    - BUG/MEDIUM: mux-h2: properly consider the peer's advertised max-concurrent-streams
    - MINOR: xref: Add missing barriers.
    - MINOR: muxes: Don't bother to LIST_DEL(&conn->list) before calling conn_free().
    - MINOR: debug: Add an option that causes random allocation failures.
    - BUG/MEDIUM: backend: always release the previous connection into its own target srv_list
    - BUG/MEDIUM: htx: check the HTX compatibility in dynamic use-backend rules
    - BUG/MINOR: tune.fail-alloc: Don't forget to initialize ret.
    - BUG/MINOR: backend: check srv_conn before dereferencing it
    - BUG/MEDIUM: mux-h2: always omit :scheme and :path for the CONNECT method
    - BUG/MEDIUM: mux-h2: always set :authority on request output
    - BUG/MEDIUM: stream: Don't forget to free s->unique_id in stream_free().
    - BUG/MINOR: threads: fix the process range of thread masks
    - BUG/MINOR: config: fix bind line thread mask validation
    - CLEANUP: threads: fix misleading comment about all_threads_mask
    - CLEANUP: threads: use nbits to calculate the thread mask
    - OPTIM: listener: optimize cache-line packing for struct listener
    - MINOR: tools: improve the popcount() operation
    - MINOR: config: keep an all_proc_mask like we have all_threads_mask
    - MINOR: global: add proc_mask() and thread_mask()
    - MINOR: config: simplify bind_proc processing using proc_mask()
    - MINOR: threads: make use of thread_mask() to simplify some thread calculations
    - BUG/MINOR: compression: properly report compression stats in HTX mode
    - BUG/MINOR: task: close a tiny race in the inter-thread wakeup
    - BUG/MAJOR: config: verify that targets of track-sc and stick rules are present
    - BUG/MAJOR: spoe: verify that backends used by SPOE cover all their callers' processes
    - BUG/MAJOR: htx/backend: Make all tests on HTTP messages compatible with HTX
    - BUG/MINOR: config: make sure to count the error on incorrect track-sc/stick rules
    - DOC: ssl: Clarify when pre TLSv1.3 cipher can be used
    - DOC: ssl: Stop documenting ciphers example to use
    - BUG/MINOR: spoe: do not assume agent->rt is valid on exit
    - BUG/MINOR: lua: initialize the correct idle conn lists for the SSL sockets
    - BUG/MEDIUM: spoe: initialization depending on nbthread must be done last
    - BUG/MEDIUM: server: initialize the idle conns list after parsing the config
    - BUG/MEDIUM: server: initialize the orphaned conns lists and tasks at the end
    - MINOR: config: make MAX_PROCS configurable at build time
    - BUG/MAJOR: spoe: Don't try to get agent config during SPOP healthcheck
    - BUG/MINOR: config: Reinforce validity check when a process number is parsed
    - BUG/MEDIUM: peers: check that p->srv actually exists before using p->srv->use_ssl
    - CONTRIB: contrib/prometheus-exporter: Add a Prometheus exporter for HAProxy
    - BUG/MINOR: mux-h1: verify the request's version before dropping connection: keep-alive
    - BUG: 51d: In Hash Trie, multi header matching was affected by the header names stored globaly.
    - MEDIUM: 51d: Enabled multi threaded operation in the 51Degrees module.
    - BUG/MAJOR: stream: avoid double free on unique_id
    - BUILD/MINOR: stream: avoid a build warning with threads disabled
    - BUILD/MINOR: tools: fix build warning in the date conversion functions
    - BUILD/MINOR: peers: remove an impossible null test in intencode()
    - BUILD/MINOR: htx: fix some potential null-deref warnings with http_find_stline
    - BUG/MEDIUM: peers: Missing peer initializations.
    - BUG/MEDIUM: http_fetch: fix the "base" and "base32" fetch methods in HTX mode
    - BUG/MEDIUM: proto_htx: Fix data size update if end of the cookie is removed
    - BUG/MEDIUM: http_fetch: fix "req.body_len" and "req.body_size" fetch methods in HTX mode
    - BUILD/MEDIUM: initcall: Fix build on MacOS.
    - BUG/MEDIUM: mux-h2/htx: Always set CS flags before exiting h2_rcv_buf()
    - MINOR: h2/htx: Set the flag HTX_SL_F_BODYLESS for messages without body
    - BUG/MINOR: mux-h1: Add "transfer-encoding" header on outgoing requests if needed
    - BUG/MINOR: mux-h2: Don't add ":status" pseudo-header on trailers
    - BUG/MINOR: proto-htx: Consider a XFER_LEN message as chunked by default
    - BUG/MEDIUM: h2/htx: Correctly handle interim responses when HTX is enabled
    - MINOR: mux-h2: Set HTX extra value when possible
    - BUG/MEDIUM: htx: count the amount of copied data towards the final count
    - MINOR: mux-h2: make the H2 MAX_FRAME_SIZE setting configurable
    - BUG/MEDIUM: mux-h2/htx: send an empty DATA frame on empty HTX trailers
    - BUG/MEDIUM: servers: Use atomic operations when handling curr_idle_conns.
    - BUG/MEDIUM: servers: Add a per-thread counter of idle connections.
    - MINOR: fd: add a new my_closefrom() function to close all FDs
    - MINOR: checks: use my_closefrom() to close all FDs
    - MINOR: fd: implement an optimised my_closefrom() function
    - BUG/MINOR: fd: make sure my_closefrom() doesn't miss some FDs
    - BUG/MAJOR: fd/threads, task/threads: ensure all spin locks are unlocked
    - BUG/MAJOR: listener: Make sure the listener exist before using it.
    - MINOR: fd: Use closefrom() as my_closefrom() if supported.
    - BUG/MEDIUM: mux-h1: Report the right amount of data xferred in h1_rcv_buf()
    - BUG/MINOR: channel: Set CF_WROTE_DATA when outgoing data are skipped
    - MINOR: htx: Add function to drain data from an HTX message
    - MINOR: channel/htx: Add function to skips output bytes from an HTX channel
    - BUG/MAJOR: cache/htx: Set the start-line offset when a cached object is served
    - BUG/MEDIUM: cache: Get objects from the cache only for GET and HEAD requests
    - BUG/MINOR: cache/htx: Return only the headers of cached objects to HEAD requests
    - BUG/MINOR: mux-h1: Always initilize h1m variable in h1_process_input()
    - BUG/MEDIUM: proto_htx: Fix functions applying regex filters on HTX messages
    - BUG/MEDIUM: h2: advertise to servers that we don't support push
    - MINOR: standard: Add a function to parse uints (dotted notation).
    - MINOR: arg: Add support for ARGT_PBUF_FNUM arg type.
    - MINOR: http_fetch: add "req.ungrpc" sample fetch for gRPC.
    - MINOR: sample: Add two sample converters for protocol buffers.
    - DOC: sample: Add gRPC related documentation.

6 years agoDOC: sample: Add gRPC related documentation.
Frédéric Lécaille [Tue, 26 Feb 2019 14:02:35 +0000 (15:02 +0100)] 
DOC: sample: Add gRPC related documentation.

Add documentation for "req.ungrpc" sample fetch method and "varint"
and "svarint" two new protocol buffers specific converters.

6 years agoMINOR: sample: Add two sample converters for protocol buffers.
Frédéric Lécaille [Tue, 26 Feb 2019 13:09:08 +0000 (14:09 +0100)] 
MINOR: sample: Add two sample converters for protocol buffers.

Add "varint" to convert all the protocol buffers binary varints excepted the signed
ones ("sint32" and "sint64") to an integer. The binary signed varints may be
converted to an integer with "svarint" converter implemented by this patch.
These two new converters do not take any argument.

6 years agoMINOR: http_fetch: add "req.ungrpc" sample fetch for gRPC.
Frédéric Lécaille [Mon, 25 Feb 2019 14:30:36 +0000 (15:30 +0100)] 
MINOR: http_fetch: add "req.ungrpc" sample fetch for gRPC.

This patch implements "req.ungrpc" sample fetch method to decode and
parse a gRPC request. It takes only one argument: a protocol buffers
field number to identify the protocol buffers message number to be looked up.
This argument is a sort of path in dotted notation to the terminal field number
to be retrieved.

  ex:
    req.ungrpc(1.2.3.4)

This sample fetch catch the data in raw mode, without interpreting them.
Some protocol buffers specific converters may be used to convert the data
to the correct type.

6 years agoMINOR: arg: Add support for ARGT_PBUF_FNUM arg type.
Frédéric Lécaille [Mon, 25 Feb 2019 14:20:35 +0000 (15:20 +0100)] 
MINOR: arg: Add support for ARGT_PBUF_FNUM arg type.

This new argument type is used to parse Protocol Buffers field number
with dotted notation (e.g: 1.2.3.4).

6 years agoMINOR: standard: Add a function to parse uints (dotted notation).
Frédéric Lécaille [Mon, 25 Feb 2019 14:04:22 +0000 (15:04 +0100)] 
MINOR: standard: Add a function to parse uints (dotted notation).

This function is useful to parse strings made of unsigned integers
and to allocate a C array of unsigned integers from there.
For instance this function allocates this array { 1, 2, 3, 4, } from
this string: "1.2.3.4".

6 years agoBUG/MEDIUM: h2: advertise to servers that we don't support push
Willy Tarreau [Tue, 26 Feb 2019 15:01:52 +0000 (16:01 +0100)] 
BUG/MEDIUM: h2: advertise to servers that we don't support push

The h2c_send_settings() function was initially made to serve on the
frontend. Here we don't need to advertise that we don't support PUSH
since we don't do that ourselves. But on the backend side it's
different because PUSH is enabled by default so we must announce that
we don't want the server to use it.

This must be backported to 1.9.

6 years agoBUG/MEDIUM: proto_htx: Fix functions applying regex filters on HTX messages
Christopher Faulet [Tue, 26 Feb 2019 14:36:05 +0000 (15:36 +0100)] 
BUG/MEDIUM: proto_htx: Fix functions applying regex filters on HTX messages

The HTX functions htx_apply_filter_to_req_headers() and
htx_apply_filter_to_resp_headers() contain 2 bugs. The first one is about the
matching on each header. The chunk 'hdr' used to format a full header line was
never reset. The second bug appears when we try to replace or remove a
header. The variable ctx was not fully initialized, leading to sefaults.

This patch must be backported to 1.9.

6 years agoBUG/MINOR: mux-h1: Always initilize h1m variable in h1_process_input()
Christopher Faulet [Tue, 26 Feb 2019 13:45:05 +0000 (14:45 +0100)] 
BUG/MINOR: mux-h1: Always initilize h1m variable in h1_process_input()

It is used at the end of the function to know if the end of the message was
reached. So we must be sure to always initialize it.

This patch must be backported to 1.9.

6 years agoBUG/MINOR: cache/htx: Return only the headers of cached objects to HEAD requests
Christopher Faulet [Mon, 25 Feb 2019 10:08:34 +0000 (11:08 +0100)] 
BUG/MINOR: cache/htx: Return only the headers of cached objects to HEAD requests

The body of a cached object must not be sent in response to a HEAD request. This
works for the legacy HTTP because the parsing is performed by HTTP analyzers
_AND_ because the connection is closed at the end of the transaction. So the
body is ignored. But the applet send it. For the HTX, the applet must skip the
body explicitly.

This patch must be backported to 1.9.

6 years agoBUG/MEDIUM: cache: Get objects from the cache only for GET and HEAD requests
Christopher Faulet [Mon, 25 Feb 2019 09:59:33 +0000 (10:59 +0100)] 
BUG/MEDIUM: cache: Get objects from the cache only for GET and HEAD requests

Only responses for GET requests are stored in the cache. But there is no check
on the method during the lookup. So it is possible to retrieve an object from
the cache independently of the method, from the time the key of the object
matches. Now, lookups are performed only for GET and HEAD requests.

This patch must be backportedi in 1.9.

6 years agoBUG/MAJOR: cache/htx: Set the start-line offset when a cached object is served
Christopher Faulet [Mon, 25 Feb 2019 10:15:08 +0000 (11:15 +0100)] 
BUG/MAJOR: cache/htx: Set the start-line offset when a cached object is served

When the function htx_add_stline() is used, this offset is automatically set
when necessary. But the HTX cache applet adds all header blocks of the responses
manually, including the start-line. So its offset must be explicitly set by the
applet.

When everything goes well, the HTTP analyzer http_wait_for_response() looks for
the start-line in the HTX messages, calling http_find_stline(). If necessary,
the start-line offet will also be automatically set during this stage. So the
bug of the HTX cache applet does not hurt most of the time. But, when an error
occurred, HTTP responses analyzers can be bypassed. In such caese, the
start-line offset of cached responses remains unset.

Some part of the code relies on the start-line offset to process the HTX
messages. Among others, when H2 responses are sent to clients, the H2
multiplexer read the start-line without any check, because it _MUST_ always be
there. if its offset is not set, a NULL pointer is dereferenced leading to a
segfault.

The patch must be backported to 1.9.

6 years agoMINOR: channel/htx: Add function to skips output bytes from an HTX channel
Christopher Faulet [Mon, 25 Feb 2019 09:44:51 +0000 (10:44 +0100)] 
MINOR: channel/htx: Add function to skips output bytes from an HTX channel

It is the HTX version of co_skip(). Internally, It uses the function htx_drain().

It will be used by other commits to fix bugs, so it must be backported to 1.9.

6 years agoMINOR: htx: Add function to drain data from an HTX message
Christopher Faulet [Mon, 25 Feb 2019 09:23:19 +0000 (10:23 +0100)] 
MINOR: htx: Add function to drain data from an HTX message

The function htx_drain() can now be used to drain data from an HTX message.

It will be used by other commits to fix bugs, so it must be backported to 1.9.

6 years agoBUG/MINOR: channel: Set CF_WROTE_DATA when outgoing data are skipped
Christopher Faulet [Mon, 25 Feb 2019 14:50:12 +0000 (15:50 +0100)] 
BUG/MINOR: channel: Set CF_WROTE_DATA when outgoing data are skipped

in co_skip(), the flag CF_WRITE_PARTIAL is set on the channel. The flag
CF_WROTE_DATA must also be set to notify the channel some data were sent.

This patch must be backported to 1.9.

6 years agoBUG/MEDIUM: mux-h1: Report the right amount of data xferred in h1_rcv_buf()
Christopher Faulet [Mon, 25 Feb 2019 14:29:51 +0000 (15:29 +0100)] 
BUG/MEDIUM: mux-h1: Report the right amount of data xferred in h1_rcv_buf()

h1_rcv_buf() must return the amount of data copied in the channel's buffer and
not the number of bytes parsed. Because this value is used during the fast
forwarding to decrement to_forward value, returning the wrong value leads to
undefined behaviours.

This patch must be backported to 1.9.

6 years agoMINOR: fd: Use closefrom() as my_closefrom() if supported.
Olivier Houchard [Mon, 25 Feb 2019 13:26:54 +0000 (14:26 +0100)] 
MINOR: fd: Use closefrom() as my_closefrom() if supported.

Add a new option, USE_CLOSEFROM. If set, it is assumed the system provides
a closefrom() function, so use it.
It is only implicitely used on FreeBSD for now, it should work on
OpenBSD/NetBSD/DragonflyBSD/Solaris too, but as I have no such system to
test it, I'd rather leave it disabled by default. Users can add USE_CLOSEFROM
explicitely on their make command line to activate it.

6 years agoBUG/MAJOR: listener: Make sure the listener exist before using it.
Olivier Houchard [Mon, 25 Feb 2019 15:18:16 +0000 (16:18 +0100)] 
BUG/MAJOR: listener: Make sure the listener exist before using it.

In listener_accept(), make sure we have a listener before attempting to
use it.
An another thread may have closed the FD meanwhile, and set fdtab[fd].owner
to NULL.
As the listener is not free'd, it is ok to attempt to accept() a new
connection even if the listener was closed. At worst the fd has been
reassigned to another connection, and accept() will fail anyway.

Many thanks to Richard Russo for reporting the problem, and suggesting the
fix.

This should be backported to 1.9 and 1.8.

6 years agoBUG/MAJOR: fd/threads, task/threads: ensure all spin locks are unlocked
Richard Russo [Wed, 20 Feb 2019 20:43:45 +0000 (12:43 -0800)] 
BUG/MAJOR: fd/threads, task/threads: ensure all spin locks are unlocked

Calculate if the fd or task should be locked once, before locking, and
reuse the calculation when determing when to unlock.

Fixes a race condition added in 87d54a9a for fds, and b20aa9ee for tasks,
released in 1.9-dev4. When one thread modifies thread_mask to be a single
thread for a task or fd while a second thread has locked or is waiting on a
lock for that task or fd, the second thread will not unlock it.  For FDs,
this is observable when a listener is polled by multiple threads, and is
closed while those threads have events pending.  For tasks, this seems
possible, where task_set_affinity is called, but I did not observe it.

This must be backported to 1.9.

6 years agoBUG/MINOR: fd: make sure my_closefrom() doesn't miss some FDs
Willy Tarreau [Fri, 22 Feb 2019 08:07:42 +0000 (09:07 +0100)] 
BUG/MINOR: fd: make sure my_closefrom() doesn't miss some FDs

The optimized my_closefrom() implementation introduced with previous commit
9188ac60e ("MINOR: fd: implement an optimised my_closefrom() function")
has a small bug causing it to miss some FDs at the end of each batch.
The reason is that poll() returns the number of non-zero events, so
it contains the size of the batch minus the FDs to close. Thus if the
FDs to close are at the beginning they'll be seen but if they're at the
end after all other closed ones, the returned count will not cover them.

No backport is needed.

6 years agoMINOR: fd: implement an optimised my_closefrom() function
Willy Tarreau [Thu, 21 Feb 2019 21:12:47 +0000 (22:12 +0100)] 
MINOR: fd: implement an optimised my_closefrom() function

The idea is that poll() can set the POLLNVAL flag for each invalid
FD in a pollfd list. Thus this function makes use of poll() when
compiled in, and builds lists of up to 1024 FDs at once, checks the
output and only closes those which do not have this flag set. Tests
show that this is about twice as fast as blindly calling close() for
each closed fd.

6 years agoMINOR: checks: use my_closefrom() to close all FDs
Willy Tarreau [Thu, 21 Feb 2019 21:22:06 +0000 (22:22 +0100)] 
MINOR: checks: use my_closefrom() to close all FDs

Instead of looping on all FDs, let's use my_closefrom() which does it
respecting the current process' limits and possibly doing it more
efficiently.

6 years agoMINOR: fd: add a new my_closefrom() function to close all FDs
Willy Tarreau [Thu, 21 Feb 2019 21:19:17 +0000 (22:19 +0100)] 
MINOR: fd: add a new my_closefrom() function to close all FDs

This is a naive implementation of closefrom() which closes all FDs
starting from the one passed in argument. closefrom() is not provided
on all operating systems, and other versions will follow.

6 years agoBUG/MEDIUM: servers: Add a per-thread counter of idle connections.
Olivier Houchard [Mon, 18 Feb 2019 15:41:17 +0000 (16:41 +0100)] 
BUG/MEDIUM: servers: Add a per-thread counter of idle connections.

Add a per-thread counter of idling connections, and use it to determine
how many connections we should kill after the timeout, instead of using
the global counter, or we're likely to just kill most of the connections.

This should be backported to 1.9.

6 years agoBUG/MEDIUM: servers: Use atomic operations when handling curr_idle_conns.
Olivier Houchard [Fri, 15 Feb 2019 17:49:15 +0000 (18:49 +0100)] 
BUG/MEDIUM: servers: Use atomic operations when handling curr_idle_conns.

Use atomic operations when dealing with srv->curr_idle_conns, as it's shared
between threads, otherwise we could get inconsistencies.

This should be backported to 1.9.

6 years agoBUG/MEDIUM: mux-h2/htx: send an empty DATA frame on empty HTX trailers
Willy Tarreau [Thu, 21 Feb 2019 17:16:35 +0000 (18:16 +0100)] 
BUG/MEDIUM: mux-h2/htx: send an empty DATA frame on empty HTX trailers

When chunked-encoding is used in HTX mode, a trailers HTX block is always
made due to the way trailers are currently implemented (verbatim copy of
the H1 representation). Because of this it's not possible to know when
processing data that we've reached the end of the stream, and it's up
to the function encoding the trailers (h2s_htx_make_trailers) to put the
end of stream. But when there are no trailers and only an empty HTX block,
this one cannot produce a HEADERS frame, thus it cannot send the END_STREAM
flag either, leaving the other end with an incomplete message, waiting for
either more data or some trailers. This is particularly visible with POST
requests where the server continues to wait.

What this patch does is transform the HEADERS frame into an empty DATA
frame when meeting an empty trailers block. It is possible to do this
because we've not sent any trailers so the other end is still waiting
for DATA frames. The check is made after attempting to encode the list
of headers, so as to minimize the specific code paths.

Thanks to Dragan Dosen for reporting the issue with a reproducer.

This fix must be backported to 1.9.

6 years agoMINOR: mux-h2: make the H2 MAX_FRAME_SIZE setting configurable
Willy Tarreau [Thu, 21 Feb 2019 12:24:36 +0000 (13:24 +0100)] 
MINOR: mux-h2: make the H2 MAX_FRAME_SIZE setting configurable

This creates a new tunable "tune.h2.max-frame-size" to adjust the
advertised max frame size. When not set it still defaults to the buffer
size. It is convenient to advertise sizes lower than the buffer size,
for example when using very large buffers.

6 years agoBUG/MEDIUM: htx: count the amount of copied data towards the final count
Willy Tarreau [Thu, 21 Feb 2019 14:06:30 +0000 (15:06 +0100)] 
BUG/MEDIUM: htx: count the amount of copied data towards the final count

Currently htx_xfer_blks() respects the <count> limit for each block
instead of for the sum of the transfered blocks. This causes it to
return slightly more than requested when both headers and data are
present in the source buffer, which happens early in the transfer
when the reserve is still active. Thus with large enough headers,
the reserve will not be respected.

Note that this function is only called from h2_rcv_buf() thus this only
affects data entering over H2 (H2 requests or H2 responses).

This fix must be backported to 1.9.

6 years agoMINOR: mux-h2: Set HTX extra value when possible
Christopher Faulet [Mon, 18 Feb 2019 15:04:35 +0000 (16:04 +0100)] 
MINOR: mux-h2: Set HTX extra value when possible

For now, this can be only done when a content-length is specified. In fact, it
is the same value than h2s->body_len, the remaining body length according to
content-length. Setting this field allows the fast forwarding at the channel
layer, improving significantly data transfer for big objects.

This patch may be backported to 1.9.

6 years agoBUG/MEDIUM: h2/htx: Correctly handle interim responses when HTX is enabled
Christopher Faulet [Tue, 19 Feb 2019 14:14:23 +0000 (15:14 +0100)] 
BUG/MEDIUM: h2/htx: Correctly handle interim responses when HTX is enabled

1xx responses does not work in HTTP2 when the HTX is enabled. First of all, when
a response is parsed, only one HEADERS frame is expected. So when an interim
response is received, the flag H2_SF_HEADERS_RCVD is set and the next HEADERS
frame (for another interim repsonse or the final one) is parsed as a trailers
one. Then when the response is sent, because an EOM block is found at the end of
the interim HTX response, the ES flag is added on the frame, closing too early
the stream. Here, it is a design problem of the HTX. Iterim responses are
considered as full messages, leading to some ambiguities when HTX messages are
processed. This will not be fixed now, but we need to keep it in mind for future
improvements.

To fix the parsing bug, the flag H2_MSGF_RSP_1XX is added when the response
headers are decoded. When this flag is set, an EOM block is added into the HTX
message, despite the fact that there is no ES flag on the frame. And we don't
set the flag H2_SF_HEADERS_RCVD on the corresponding H2S. So the next HEADERS
frame will not be parsed as a trailers one.

To fix the sending bug, the ES flag is not set on the frame when an interim
response is processed and the flag H2_SF_HEADERS_SENT is not set on the
corresponding H2S.

This patch must be backported to 1.9.

6 years agoBUG/MINOR: proto-htx: Consider a XFER_LEN message as chunked by default
Christopher Faulet [Mon, 18 Feb 2019 10:35:02 +0000 (11:35 +0100)] 
BUG/MINOR: proto-htx: Consider a XFER_LEN message as chunked by default

An HTX message with a known body length is now considered by default as
chunked. It means the header "content-length" must be found to consider it as a
non-chunked message. Before, it was the reverse, the message was considered with
a content length by default. But it is a bug for HTTP/2 messages. There is no
chunked transfer encoding in HTTP/2 but internally messages without content
length are considered as chunked. It eases HTTP/1 <-> HTTP/2 conversions.

This patch must be backported to 1.9.

6 years agoBUG/MINOR: mux-h2: Don't add ":status" pseudo-header on trailers
Christopher Faulet [Mon, 18 Feb 2019 10:22:35 +0000 (11:22 +0100)] 
BUG/MINOR: mux-h2: Don't add ":status" pseudo-header on trailers

It is a cut-paste bug. Pseudo-header fields MUST NOT appear in trailers.

This patch must be backported to 1.9.

6 years agoBUG/MINOR: mux-h1: Add "transfer-encoding" header on outgoing requests if needed
Christopher Faulet [Mon, 18 Feb 2019 09:33:16 +0000 (10:33 +0100)] 
BUG/MINOR: mux-h1: Add "transfer-encoding" header on outgoing requests if needed

As for outgoing response, if an HTTP/1.1 or above request is sent to a server
with neither the headers "content-length" nor "transfer-encoding", it is
considered as a chunked request and the header "transfer-encoding: chunked" is
automatically added. Of course, it is only true for requests with a
body. Concretely, it only happens for incoming HTTP/2 requests sent to an
HTTP/1.1 server.

This patch must be backported to 1.9.

6 years agoMINOR: h2/htx: Set the flag HTX_SL_F_BODYLESS for messages without body
Christopher Faulet [Mon, 18 Feb 2019 09:12:56 +0000 (10:12 +0100)] 
MINOR: h2/htx: Set the flag HTX_SL_F_BODYLESS for messages without body

This information is usefull to know if a body is expected or not, regardless the
presence or not of the header "Content-Length" and its value. Once the ES flag
is set on the header frame or when the content length is 0, we can safely add
the flag HTX_SL_F_BODYLESS on the HTX start-line.

Among other things, it will help the mux-h1 to know if it should add TE header
or not. It will also help the HTTP compression filter.

This patch must be backported to 1.9 because a bug fix depends on it.

6 years agoBUG/MEDIUM: mux-h2/htx: Always set CS flags before exiting h2_rcv_buf()
Christopher Faulet [Thu, 14 Feb 2019 14:12:14 +0000 (15:12 +0100)] 
BUG/MEDIUM: mux-h2/htx: Always set CS flags before exiting h2_rcv_buf()

It is especially important when some data are blocked in the RX buf and the
channel buffer is already full. In such case, instead of exiting the function
directly, we need to set right flags on the conn_stream. CS_FL_RCV_MORE and
CS_FL_WANT_ROOM must be set, otherwise, the stream-interface will subscribe to
receive events, thinking it is not blocked.

This bug leads to connection freeze when everything was received with some data
blocked in the RX buf and a channel full.

This patch must be backported to 1.9.

6 years agoBUILD/MEDIUM: initcall: Fix build on MacOS.
Olivier Houchard [Wed, 13 Feb 2019 15:22:17 +0000 (16:22 +0100)] 
BUILD/MEDIUM: initcall: Fix build on MacOS.

MacOS syntax for sections is a bit different, so implement it.
(see issue #42).

This should be backported to 1.9.

6 years agoBUG/MEDIUM: http_fetch: fix "req.body_len" and "req.body_size" fetch methods in HTX...
Dragan Dosen [Thu, 14 Feb 2019 11:30:53 +0000 (12:30 +0100)] 
BUG/MEDIUM: http_fetch: fix "req.body_len" and "req.body_size" fetch methods in HTX mode

When in HTX mode, in functions smp_fetch_body_len() and
smp_fetch_body_size() we were subtracting the size of each header block
from the total size htx->data to calculate the size of body, and that
could result in wrong calculated value.

To avoid this, we now loop on blocks to sum up the size of only those
that are of type HTX_BLK_DATA.

This patch must be backported to 1.9.

6 years agoBUG/MEDIUM: proto_htx: Fix data size update if end of the cookie is removed
Christopher Faulet [Tue, 12 Feb 2019 13:29:57 +0000 (14:29 +0100)] 
BUG/MEDIUM: proto_htx: Fix data size update if end of the cookie is removed

When client-side or server-side cookies are parsed, if the end of the cookie
line is removed, the HTX message must be updated. The length of the HTX block is
decreased and the data size of the HTX message is modified accordingly. The
update of the HTX block was ok but the update of the HTX message was wrong,
leading to undefined behaviours during the data forwarding. One of possible
effect was a freeze of the connection and no data forward.

This patch must be backported in 1.9.

6 years agoBUG/MEDIUM: http_fetch: fix the "base" and "base32" fetch methods in HTX mode
Dragan Dosen [Tue, 12 Feb 2019 18:50:31 +0000 (19:50 +0100)] 
BUG/MEDIUM: http_fetch: fix the "base" and "base32" fetch methods in HTX mode

The resulting value produced in functions smp_fetch_base() and
smp_fetch_base32() was wrong when in HTX mode.

This patch also adds the semicolon at the end of the for-loop line, used
in function smp_fetch_path(), since it's actually with no body.

This must be backported to 1.9.

6 years agoBUG/MEDIUM: peers: Missing peer initializations.
Frédéric Lécaille [Tue, 12 Feb 2019 18:12:32 +0000 (19:12 +0100)] 
BUG/MEDIUM: peers: Missing peer initializations.

Initialize ->srv peer field for all the peers, the local peer included.
Indeed, a haproxy process needs to connect to the local peer of a remote
process. Furthermore, when a "peer" or "server" line is parsed by parse_server()
the address must be copied to ->addr field of the peer object only if this address
has been also parsed by parse_server(). This is not the case if this address belongs
to the local peer and is provided on a "server" line.

After having parsed the "peer" or "server" lines of a peer
sections, the ->srv part of all the peer must be initialized for SSL, if
enabled. Same thing for the binding part.

Revert 1417f0b commit which is no more required.

No backport is needed, this is purely 2.0.

6 years agoBUILD/MINOR: htx: fix some potential null-deref warnings with http_find_stline
Willy Tarreau [Tue, 12 Feb 2019 11:02:27 +0000 (12:02 +0100)] 
BUILD/MINOR: htx: fix some potential null-deref warnings with http_find_stline

http_find_stline() carefully verifies that it finds a start line otherwise
returns NULL when not found. But a few calling functions ignore this NULL
in return and dereference this pointer without checking. Let's add the
test where needed in the callers. If it turns out that over the long term
a start line is mandatory, then the test will be removed and the faulty
function will have to be simplified.

This must be backported to 1.9.

6 years agoBUILD/MINOR: peers: remove an impossible null test in intencode()
Willy Tarreau [Tue, 12 Feb 2019 10:59:35 +0000 (11:59 +0100)] 
BUILD/MINOR: peers: remove an impossible null test in intencode()

intencode() tests for the nullity of the target pointer passed in
argument, but the code calling intencode() never does so and happily
dereferences it. gcc at -O3 detects this as a potential null deref.
Let's remove this incorrect and misleading test. If this pointer was
null, the code would already crash in the calling functions.

This must be backported to stable versions.

6 years agoBUILD/MINOR: tools: fix build warning in the date conversion functions
Willy Tarreau [Tue, 12 Feb 2019 10:26:29 +0000 (11:26 +0100)] 
BUILD/MINOR: tools: fix build warning in the date conversion functions

Some gcc versions emit potential null deref warnings at -O3 in
date2str_log(), gmt2str_log() and localdate2str_log() after utoa_pad()
because this function may return NULL if its size argument is too small
for the integer value. And it's true that we can't guarantee that the
input number is always valid.

This must be backported to all stable versions.

6 years agoBUILD/MINOR: stream: avoid a build warning with threads disabled
Willy Tarreau [Tue, 12 Feb 2019 09:59:32 +0000 (10:59 +0100)] 
BUILD/MINOR: stream: avoid a build warning with threads disabled

gcc 6+ complains about a possible null-deref here due to the test in
objt_server() :

       if (objt_server(s->target))
           HA_ATOMIC_ADD(&objt_server(s->target)->counters.retries, 1);

Let's simply change it to __objt_server(). This can be backported to
1.9 and 1.8.

6 years agoBUG/MAJOR: stream: avoid double free on unique_id
Willy Tarreau [Sun, 10 Feb 2019 17:49:37 +0000 (18:49 +0100)] 
BUG/MAJOR: stream: avoid double free on unique_id

Commit 32211a1 ("BUG/MEDIUM: stream: Don't forget to free
s->unique_id in stream_free().") addressed a memory leak but in
exchange may cause double-free due to the fact that after freeing
s->unique_id it doesn't null it and then calls http_end_txn()
which frees it again. Thus the process quickly crashes at runtime.

This fix must be backported to all stable branches where the
aforementioned patch was backported.

6 years agoMEDIUM: 51d: Enabled multi threaded operation in the 51Degrees module.
Ben51Degrees [Tue, 5 Feb 2019 13:24:00 +0000 (13:24 +0000)] 
MEDIUM: 51d: Enabled multi threaded operation in the 51Degrees module.

The existing threading flag in the 51Degrees API
(FIFTYONEDEGREES_NO_THREADING) has now been mapped to the HAProxy
threading flag (USE_THREAD), and the 51Degrees module code has been made
thread safe.
In Pattern, the cache is now locked with a spin lock from hathreads.h
using a new lable 'OTHER_LOCK'. The workset pool is now created with the
same size as the number of threads to avoid any time waiting on a
worket.
In Hash Trie, the global device offsets structure is only used in single
threaded operation. Multi threaded operation creates a new offsets
structure in each thread.

6 years agoBUG: 51d: In Hash Trie, multi header matching was affected by the header names stored...
Ben51Degrees [Tue, 5 Feb 2019 13:23:06 +0000 (13:23 +0000)] 
BUG: 51d: In Hash Trie, multi header matching was affected by the header names stored globaly.

Some logic around mutli header matching in Hash Trie has been improved
where only the name of the most important header was stored in the
global heade_names structure. Now all headers are stored, so are used in
the mutli header matching correctly.

6 years agoBUG/MINOR: mux-h1: verify the request's version before dropping connection: keep...
Willy Tarreau [Fri, 8 Feb 2019 14:35:38 +0000 (15:35 +0100)] 
BUG/MINOR: mux-h1: verify the request's version before dropping connection: keep-alive

The mux h1 properly avoid to set "connection: keep-alive" when the response
is in HTTP/1.1 but it forgot to check the request's version. Thus when the
client requests using HTTP/1.0 and connection: keep-alive (like ab does),
the response is in 1.1 with no keep-alive and ab waits for the close without
checking for the content-length. Response headers actually depend on the
recipient, thus on both request and response's version.

This patch must be backported to 1.9.

6 years agoCONTRIB: contrib/prometheus-exporter: Add a Prometheus exporter for HAProxy
Christopher Faulet [Thu, 7 Feb 2019 14:38:42 +0000 (15:38 +0100)] 
CONTRIB: contrib/prometheus-exporter: Add a Prometheus exporter for HAProxy

It has been developped as a service applet. Internally, it is called
"promex". To build HAProxy with the promex service, you should use the Makefile
variable "EXTRA_OBJS". To be used, it must be enabled in the configuration with
an "http-request" rule and the corresponding HTTP proxy must enable the HTX
support. For instance:

    frontend test
        mode http
        ...
option http-use-htx
http-request use-service prometheus-exporter if { path /metrics }
        ...

See contrib/prometheus-exporter/README for details.

6 years agoBUG/MEDIUM: peers: check that p->srv actually exists before using p->srv->use_ssl
Willy Tarreau [Fri, 8 Feb 2019 09:22:31 +0000 (10:22 +0100)] 
BUG/MEDIUM: peers: check that p->srv actually exists before using p->srv->use_ssl

Commit 1055e687a ("MINOR: peers: Make outgoing connection to SSL/TLS
peers work.") introduced an "srv" field in the peers, which points to
the equivalent server to hold SSL settings. This one is not set when
the peer is local so we must always test it before testing p->srv->use_ssl
otherwise haproxy dies during reloads.

No backport is needed, this is purely 2.0.

6 years agoBUG/MINOR: config: Reinforce validity check when a process number is parsed
Christopher Faulet [Thu, 7 Feb 2019 15:29:41 +0000 (16:29 +0100)] 
BUG/MINOR: config: Reinforce validity check when a process number is parsed

Now, in the function parse_process_number(), when a process number or a set of
processes is parsed, an error is triggered if an invalid character is found. It
means following syntaxes are not forbidden and will emit an alert during the
HAProxy startup:

  1a
  1/2
  1-2-3

This bug was reported on Github. See issue #36.

This patch may be backported to 1.9 and 1.8.

6 years agoBUG/MAJOR: spoe: Don't try to get agent config during SPOP healthcheck
Christopher Faulet [Thu, 7 Feb 2019 15:13:26 +0000 (16:13 +0100)] 
BUG/MAJOR: spoe: Don't try to get agent config during SPOP healthcheck

During SPOP healthchecks, a dummy appctx is used to create the HAPROXY-HELLO
frame and then to parse the AGENT-HELLO frame. No agent are attached to it. So
it is important to not rely on an agent during these stages. When HAPROXY-HELLO
frame is created, there is no problem, all accesses to an agent are
guarded. This is not true during the parsing of the AGENT-HELLO frame. Thus, it
is possible to crash HAProxy with a SPOA declaring the async or the pipelining
capability during a healthcheck.

This patch must be backported to 1.9 and 1.8.

6 years agoMINOR: config: make MAX_PROCS configurable at build time
Willy Tarreau [Thu, 7 Feb 2019 09:39:36 +0000 (10:39 +0100)] 
MINOR: config: make MAX_PROCS configurable at build time

For some embedded systems, it's pointless to have 32- or even 64- large
arrays of processes when it's known that much fewer processes will be
used in the worst case. Let's introduce this MAX_PROCS define which
contains the highest number of processes allowed to run at once. It
still defaults to LONGBITS but may be lowered.

6 years agoBUG/MEDIUM: server: initialize the orphaned conns lists and tasks at the end
Willy Tarreau [Thu, 7 Feb 2019 13:59:29 +0000 (14:59 +0100)] 
BUG/MEDIUM: server: initialize the orphaned conns lists and tasks at the end

This also depends on the nbthread count, so it must only be performed after
parsing the whole config file. As a side effect, this removes some code
duplication between servers and server-templates.

This must be backported to 1.9.

6 years agoBUG/MEDIUM: server: initialize the idle conns list after parsing the config
Willy Tarreau [Thu, 7 Feb 2019 13:46:29 +0000 (14:46 +0100)] 
BUG/MEDIUM: server: initialize the idle conns list after parsing the config

The idle conns lists are sized according to the number of threads. As such
they cannot be initialized during the parsing since nbthread can be set
later, as revealed by this simple config which randomly crashes when used.
Let's do this at the end instead.

    listen proxy
        bind :4445
        mode http
        timeout client 10s
        timeout server 10s
        timeout connect 10s
        http-reuse always
        server s1 127.0.0.1:8000

    global
        nbthread 8

This fix must be backported to 1.9 and 1.8.

6 years agoBUG/MEDIUM: spoe: initialization depending on nbthread must be done last
Willy Tarreau [Thu, 7 Feb 2019 12:40:33 +0000 (13:40 +0100)] 
BUG/MEDIUM: spoe: initialization depending on nbthread must be done last

The agent used to be configured depending on global.nbthread while nbthread
may be set after the agent is parsed. Let's move this part to the spoe_check()
function to make sure nbthread is always correct and arrays are appropriately
sized.

This fix must be backported to 1.9 and 1.8.

6 years agoBUG/MINOR: lua: initialize the correct idle conn lists for the SSL sockets
Willy Tarreau [Thu, 7 Feb 2019 13:48:24 +0000 (14:48 +0100)] 
BUG/MINOR: lua: initialize the correct idle conn lists for the SSL sockets

Commit 40a007cf2 ("MEDIUM: threads/server: Make connection list
(priv/idle/safe) thread-safe") made a copy-paste error when initializing
the Lua sockets, as the TCP one was initialized twice. Fortunately it has
no impact because the pointers are set to NULL after a memset(0) and are
not changed in between.

This must be backported to 1.9 and 1.8.

6 years agoBUG/MINOR: spoe: do not assume agent->rt is valid on exit
Willy Tarreau [Thu, 7 Feb 2019 13:22:52 +0000 (14:22 +0100)] 
BUG/MINOR: spoe: do not assume agent->rt is valid on exit

As reported by Christopher, we may call spoe_release_agent() when leaving
after an allocation failure or a config parse error. We must not assume
agent->rt is valid there as the allocation could have failed.

This should be backported to 1.9 and 1.8.

6 years agoDOC: ssl: Stop documenting ciphers example to use
Bertrand Jacquin [Sun, 3 Feb 2019 18:48:49 +0000 (18:48 +0000)] 
DOC: ssl: Stop documenting ciphers example to use

Since TLS ciphers are not well understand, it is very common pratice to
copy and paste parameters from documentation and use them as-is. Since RC4
should not be used anymore, it is wiser to link users to up to date
documnetation from Mozilla to avoid unsafe configuration in the wild.

Clarify the location of man pages for OpenSSL when missing.

6 years agoDOC: ssl: Clarify when pre TLSv1.3 cipher can be used
Bertrand Jacquin [Sun, 3 Feb 2019 18:35:25 +0000 (18:35 +0000)] 
DOC: ssl: Clarify when pre TLSv1.3 cipher can be used

This is mainly driven by the fact TLSv1.3 will have a successor at some
point.

6 years agoBUG/MINOR: config: make sure to count the error on incorrect track-sc/stick rules
Willy Tarreau [Wed, 6 Feb 2019 09:25:07 +0000 (10:25 +0100)] 
BUG/MINOR: config: make sure to count the error on incorrect track-sc/stick rules

When commit 151e1ca98 ("BUG/MAJOR: config: verify that targets of track-sc
and stick rules are present") added a check for some process inconsistencies
between rules and their stick tables, some errors resulted in a "return 0"
statement, which is taken as "no error" in some cases. Let's fix this.

This must be backported to all versions using the above commit.

6 years agoBUG/MAJOR: htx/backend: Make all tests on HTTP messages compatible with HTX
Christopher Faulet [Mon, 4 Feb 2019 11:02:18 +0000 (12:02 +0100)] 
BUG/MAJOR: htx/backend: Make all tests on HTTP messages compatible with HTX

A piece of code about the HTX was lost this summer, after the "big merge"
(htx/http2/connection layer refactoring). I forgot to keep HTX changes in the
functions connect_server() and assign_server(). So, this patch fixes "uri",
"url_param" and "hdr" LB algorithms when the HTX is enabled. It also fixes
evaluation of the "sni" expression on server lines.

This issue was reported on github. See issue #32.

This patch must be backported in 1.9.

6 years agoBUG/MAJOR: spoe: verify that backends used by SPOE cover all their callers' processes
Willy Tarreau [Tue, 5 Feb 2019 12:37:19 +0000 (13:37 +0100)] 
BUG/MAJOR: spoe: verify that backends used by SPOE cover all their callers' processes

When a filter is installed on a proxy and references spoe, we must be
absolutely certain that the whole chain is valid on a given process
when running in multi-process mode. The problem here is that if a proxy
1 runs on process 1, referencing an SPOE agent itself based on a backend
running on process 2, this last one will be completely deinited on
process 1, and will thus cause random crashes when it gets messages
from this proess.

This patch makes sure that the whole chain is valid on all of the caller's
processes.

This fix must be backported to all spoe-enabled maintained versions. It
may potentially disrupt configurations which already randomly crash.
There hardly is any intermediary solution though, such configurations
need to be fixed.

6 years agoBUG/MAJOR: config: verify that targets of track-sc and stick rules are present
Willy Tarreau [Tue, 5 Feb 2019 10:38:38 +0000 (11:38 +0100)] 
BUG/MAJOR: config: verify that targets of track-sc and stick rules are present

Stick and track-sc rules may optionally designate a table in a different
proxy. In this case, a number of verifications are made such as validating
that this proxy actually exists. However, in multi-process mode, the target
table might indeed exist but not be bound to the set of processes the rules
will execute on. This will definitely result in a random behaviour especially
if these tables do require peer synchronization, because some tasks will be
started to try to synchronize form uninitialized areas.

The typical issue looks like this :

    peers my-peers
         peer foo ...

    listen proxy
         bind-process 1
         stick on src table ip
         ...

    backend ip
         bind-process 2
         stick-table type ip size 1k peers my-peers

While it appears obvious that the example above will not work, there are
less obvious situations, such as having bind-process in a defaults section
and having a larger set of processes for the referencing proxy than the
referenced one.

The present patch adds checks for such situations by verifying that all
processes from the referencing proxy are present on the other one in all
track-sc* and stick-* rules, and in sample fetch / converters referencing
another table so that sc_inc_gpc0() and similar are safe as well.

This fix must be backported to all maintained versions. It may potentially
disrupt configurations which already randomly crash. There hardly is any
intermediary solution though, such configurations need to be fixed.

6 years agoBUG/MINOR: task: close a tiny race in the inter-thread wakeup
Willy Tarreau [Mon, 4 Feb 2019 09:26:53 +0000 (10:26 +0100)] 
BUG/MINOR: task: close a tiny race in the inter-thread wakeup

__task_wakeup() takes care of a small race that exists between threads,
but it uses a store barrier that is not sufficient since apparently the
state read after clearing the leaf_p pointer sometimes is incorrect. This
results in missed wakeups between threads competing at a high rate. Let's
use a full barrier instead to serialize the operations.

This may be backported to 1.9 though it's extremely unlikely that this
bug will ever manifest itself there.

6 years agoBUG/MINOR: compression: properly report compression stats in HTX mode
Willy Tarreau [Mon, 4 Feb 2019 10:48:03 +0000 (11:48 +0100)] 
BUG/MINOR: compression: properly report compression stats in HTX mode

When HTX support was added to HTTP compression, a set of counters was missed,
namely comp_in and comp_byp, resulting in no stats being available for compression.

This must be backported to 1.9.

6 years agoMINOR: threads: make use of thread_mask() to simplify some thread calculations
Willy Tarreau [Sat, 2 Feb 2019 17:00:17 +0000 (18:00 +0100)] 
MINOR: threads: make use of thread_mask() to simplify some thread calculations

By doing so it's visible that some fd_insert() calls were relying on
MAX_THREADS while all_threads_mask should have been more suitable.

6 years agoMINOR: config: simplify bind_proc processing using proc_mask()
Willy Tarreau [Sat, 2 Feb 2019 16:39:53 +0000 (17:39 +0100)] 
MINOR: config: simplify bind_proc processing using proc_mask()

At a number of places we used to have null tests on bind_proc for
listeners and proxies. Let's simplify all these tests by always
having the proper bits reported via proc_mask().

6 years agoMINOR: global: add proc_mask() and thread_mask()
Willy Tarreau [Sat, 2 Feb 2019 16:22:19 +0000 (17:22 +0100)] 
MINOR: global: add proc_mask() and thread_mask()

These two functions return either all_{proc,threads}_mask, or the argument.
This is used to default to all_proc_mask or all_threads_mask when not set
on bind_conf or proxies.

6 years agoMINOR: config: keep an all_proc_mask like we have all_threads_mask
Willy Tarreau [Sat, 2 Feb 2019 16:11:28 +0000 (17:11 +0100)] 
MINOR: config: keep an all_proc_mask like we have all_threads_mask

This simplifies some mask comparisons at various places where
nbits(global.nbproc) was used.

6 years agoMINOR: tools: improve the popcount() operation
Willy Tarreau [Sat, 2 Feb 2019 19:17:31 +0000 (20:17 +0100)] 
MINOR: tools: improve the popcount() operation

We'll call popcount() more often so better use a parallel method
than an iterative one. One optimal design is proposed at the site
below. It requires a fast multiplication though, but even without
it will still be faster than the iterative one, and all relevant
64 bit platforms do have a multiply unit.

     https://graphics.stanford.edu/~seander/bithacks.html

6 years agoOPTIM: listener: optimize cache-line packing for struct listener
Willy Tarreau [Sun, 3 Feb 2019 09:28:24 +0000 (10:28 +0100)] 
OPTIM: listener: optimize cache-line packing for struct listener

Some unused fields were placed early and some important ones were on
the second cache line. Let's move the proto_list and name closer to
the end of the structure to bring accept() and default_target() into
the first cache line.

6 years agoCLEANUP: threads: use nbits to calculate the thread mask
Willy Tarreau [Sat, 2 Feb 2019 16:05:03 +0000 (17:05 +0100)] 
CLEANUP: threads: use nbits to calculate the thread mask

It's pointless to do arithmetics by hand, we have a function for this.

6 years agoCLEANUP: threads: fix misleading comment about all_threads_mask
Willy Tarreau [Sat, 2 Feb 2019 16:03:41 +0000 (17:03 +0100)] 
CLEANUP: threads: fix misleading comment about all_threads_mask

This variable changed a bit after 1.8, it's never zero anymore.