]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
6 years agoBUG/MINOR: only mark connections private if NTLM is detected
Lukas Tribus [Sat, 27 Oct 2018 18:06:59 +0000 (20:06 +0200)] 
BUG/MINOR: only mark connections private if NTLM is detected

Instead of marking all connections that see a 401/407 response private
(for connection reuse), this patch detects a RFC4559/NTLM authentication
scheme and restricts the private setting to those connections.

This is so we can reuse connections with 401/407 responses with
deterministic load balancing algorithms later (which requires another fix).

This fixes the problem reported here by Elliot Barlas :

  https://discourse.haproxy.org/t/unable-to-configure-load-balancing-per-request-over-persistent-connection/3144

Should be backported to 1.8.

6 years agoMEDIUM: channel: merge back flags CF_WRITE_PARTIAL and CF_WRITE_EVENT
Willy Tarreau [Wed, 24 Oct 2018 15:17:56 +0000 (17:17 +0200)] 
MEDIUM: channel: merge back flags CF_WRITE_PARTIAL and CF_WRITE_EVENT

The behaviour of the flag CF_WRITE_PARTIAL was modified by commit
95fad5ba4 ("BUG/MAJOR: stream-int: don't re-arm recv if send fails") due
to a situation where it could trigger an immediate wake up of the other
side, both acting in loops via the FD cache. This loss has caused the
need to introduce CF_WRITE_EVENT as commit c5a9d5bf, to replace it, but
both flags express more or less the same thing and this distinction
creates a lot of confusion and complexity in the code.

Since the FD cache now acts via tasklets, the issue worked around in the
first patch no longer exists, so it's more than time to kill this hack
and to restore CF_WRITE_PARTIAL's semantics (i.e.: there has been some
write activity since we last left process_stream).

This patch mostly reverts the two commits above. Only the part making
use of CF_WROTE_DATA instead of CF_WRITE_PARTIAL to detect the loss of
data upon connection setup was kept because it's more accurate and
better suited.

6 years agoCLEANUP: tools: fix misleading comment above function LIM2A
Ioannis Cherouvim [Wed, 24 Oct 2018 07:05:19 +0000 (10:05 +0300)] 
CLEANUP: tools: fix misleading comment above function LIM2A

The function produces ASCII, but its comment was copied from U2H which
produces HTML.

6 years agoDOC: cache: Missing information about "total-max-size" and "max-object-size"
Frédéric Lécaille [Thu, 25 Oct 2018 08:46:40 +0000 (10:46 +0200)] 
DOC: cache: Missing information about "total-max-size" and "max-object-size"

6 years agoMINOR: shctx: Change max. object size type to unsigned int.
Frédéric Lécaille [Thu, 25 Oct 2018 18:31:40 +0000 (20:31 +0200)] 
MINOR: shctx: Change max. object size type to unsigned int.

This change is there to prevent implicit conversions when comparing
shctx maximum object sizes with other unsigned values.

6 years agoMINOR: cache: Avoid usage of atoi() when parsing "max-object-size".
Frédéric Lécaille [Thu, 25 Oct 2018 18:29:31 +0000 (20:29 +0200)] 
MINOR: cache: Avoid usage of atoi() when parsing "max-object-size".

With this patch we avoid parsing "max-object-size" with atoi() and we store its
value as an unsigned int to prevent bad implicit conversion issues especially
when we compare it with others unsigned value (content length).

6 years agoBUG/MINOR: ssl: Wrong usage of shctx_init().
Frédéric Lécaille [Thu, 25 Oct 2018 18:22:46 +0000 (20:22 +0200)] 
BUG/MINOR: ssl: Wrong usage of shctx_init().

With this patch we check that shctx_init() does not return 0.

Must be backported to 1.8.

6 years agoBUG/MINOR: cache: Wrong usage of shctx_init().
Frédéric Lécaille [Thu, 25 Oct 2018 18:18:59 +0000 (20:18 +0200)] 
BUG/MINOR: cache: Wrong usage of shctx_init().

With this patch we check that shctx_init() does not returns 0.
This is possible if the maxblocks argument, which is passed as an
int, is negative due to an implicit conversion.

Must be backported to 1.8.

6 years agoBUG/MINOR: cache: Crashes with "total-max-size" > 2047(MB).
Frédéric Lécaille [Thu, 25 Oct 2018 18:17:45 +0000 (20:17 +0200)] 
BUG/MINOR: cache: Crashes with "total-max-size" > 2047(MB).

With this patch we support cache size larger than 2047 (MB) and prevent haproxy from crashing when "total-max-size" is parsed as negative values by atoi().

The limit at parsing time is 4095 MB (UINT_MAX >> 20).

May be backported to 1.8.

6 years agoDOC: Update about the cache support for big objects.
Frédéric Lécaille [Tue, 23 Oct 2018 08:09:19 +0000 (10:09 +0200)] 
DOC: Update about the cache support for big objects.

6 years agoMINOR: cache: Add "max-object-size" option.
Frédéric Lécaille [Mon, 22 Oct 2018 14:59:13 +0000 (16:59 +0200)] 
MINOR: cache: Add "max-object-size" option.

This patch adds "max-object-size" option to the cache to limit
the size in bytes of the HTTP objects to be cached. When not provided,
the maximum size of an HTTP object is a 256th of the cache size.

6 years agoMINOR: shctx: Add a maximum object size parameter.
Frédéric Lécaille [Mon, 22 Oct 2018 14:21:39 +0000 (16:21 +0200)] 
MINOR: shctx: Add a maximum object size parameter.

This patch adds a new parameter to shctx_init() function to be used to
limit the size of each shared object, -1 value meaning "no limit".

6 years agoMINOR: cache: Larger HTTP objects caching.
Frédéric Lécaille [Mon, 22 Oct 2018 16:01:48 +0000 (18:01 +0200)] 
MINOR: cache: Larger HTTP objects caching.

This patch makes the capable of storing HTTP objects larger than a buffer.
It makes usage of the "block by block shared object allocation" new shctx API.

A new pointer to struct shared_block has been added to the cache applet
context to memorize the next block to be used by the HTTP cache I/O handler
http_cache_io_handler() to emit the data. Another member, named "sent" memorize
the number of bytes already sent by this handler. So, to send an object from cache,
http_cache_io_handler() must be called until "sent" counter reaches the size
of this object.

6 years agoMINOR: shctx: Shared objects block by block allocation.
Frédéric Lécaille [Mon, 22 Oct 2018 15:55:57 +0000 (17:55 +0200)] 
MINOR: shctx: Shared objects block by block allocation.

This patch makes shctx capable of storing objects in several parts,
each parts being made of several blocks. There is no more need to
walk through until reaching the end of a row to append new blocks.

A new pointer to a struct shared_block member, named last_reserved,
has been added to struct shared_block so that to memorize the last block which was
reserved by shctx_row_reserve_hot(). Same thing about "last_append" pointer which
is used to memorize the last block used by shctx_row_data_append() to store the data.

6 years agoBUG/MEDIUM: pools: fix the minimum allocation size
Willy Tarreau [Tue, 23 Oct 2018 12:40:23 +0000 (14:40 +0200)] 
BUG/MEDIUM: pools: fix the minimum allocation size

Fred reported a random crash related to the pools. This was introduced
by commit e18db9e98 ("MEDIUM: pools: implement a thread-local cache for
pool entries") because the minimum pool item size should have been
increased to 32 bytes to accommodate the 2 double-linked lists.

No backport is needed.

6 years agoMINOR: proxy: add a new option "http-use-htx"
Willy Tarreau [Mon, 22 Oct 2018 09:49:15 +0000 (11:49 +0200)] 
MINOR: proxy: add a new option "http-use-htx"

This option makes a proxy use only HTX-compatible muxes instead of the
HTTP-compatible ones for HTTP modes. It must be set on both ends, this
is checked at parsing time.

6 years agoBUG/MEDIUM: stream-int: don't set SI_FL_WAIT_ROOM on CF_READ_DONTWAIT
Christopher Faulet [Mon, 22 Oct 2018 19:34:21 +0000 (21:34 +0200)] 
BUG/MEDIUM: stream-int: don't set SI_FL_WAIT_ROOM on CF_READ_DONTWAIT

With the previous connection model, when we purposely decided to stop
receiving in order to avoid polling after a complete request was received
for example, it was needed to set SI_FL_WAIT_ROOM to prevent receive
polling from being re-armed. Now with the new subscription-based model
there is no such thing anymore and there is noone to remove this flag
either. Thus if a request takes more than one packet to come in or
spans over too many packets, this flag will cause it to wait forever.
Let's simply remove this flag now.

This patch should not be backported since older versions still need
that this flag is set here to stop receiving.

6 years agoMINOR: h1: Export some functions parsing the value of some HTTP headers
Christopher Faulet [Wed, 17 Oct 2018 09:05:51 +0000 (11:05 +0200)] 
MINOR: h1: Export some functions parsing the value of some HTTP headers

Functions parsing the value of "Connection:", "Transfer-encoding:" and
"Content-length:" headers are now exported to be used by the mux-h1.

6 years agoCLEANUP: http: Remove the unused function http_find_header
Christopher Faulet [Mon, 22 Oct 2018 07:13:31 +0000 (09:13 +0200)] 
CLEANUP: http: Remove the unused function http_find_header

6 years agoMINOR: stream_interface: Avoid calling si_cs_send/recv if not needed.
Olivier Houchard [Mon, 22 Oct 2018 14:01:09 +0000 (16:01 +0200)] 
MINOR: stream_interface: Avoid calling si_cs_send/recv if not needed.

Don't bother calling si_cs_send and si_cs_recv if we're either already
subscribe, or if the output buffer is empty for si_cs_send.

6 years agoMINOR: freq_ctr: add swrate_add_scaled() to work with large samples
Willy Tarreau [Wed, 17 Oct 2018 07:24:56 +0000 (09:24 +0200)] 
MINOR: freq_ctr: add swrate_add_scaled() to work with large samples

Some samples representing time will cover more than one sample at once
if they are units of time per time. For this we'd need to have the
ability to loop over swrate_add() multiple times but that would be
inefficient. By developing the function elevated to power N, it's
visible that some coefficients quickly disappear and that those which
remain at the first order more or less compensate each other.

Thus a simplified version of this function was added to provide a single
value for a given number of samples. Tests with multiple values, window
sizes and sample sizes have shown that it is possible to make it remain
surprisingly accurate (typical error < 0.2% over various large window
and sample sizes, even samples representing up to 1/4 of the window).

6 years agoBUILD: Makefile: add the new ERR variable to force -Werror
Willy Tarreau [Mon, 22 Oct 2018 04:22:46 +0000 (06:22 +0200)] 
BUILD: Makefile: add the new ERR variable to force -Werror

Instead of having to fiddle with the CFLAGS, let's have ERR=1 to enable
-Werror.

6 years ago[RELEASE] Released version 1.9-dev4 v1.9-dev4
Willy Tarreau [Sun, 21 Oct 2018 18:28:30 +0000 (20:28 +0200)] 
[RELEASE] Released version 1.9-dev4

Released version 1.9-dev4 with the following main changes :
    - BUILD: Allow configuration of pcre-config path
    - DOC: clarify force-private-cache is an option
    - BUG/MINOR: connection: avoid null pointer dereference in send-proxy-v2
    - REORG: http: move the code to different files
    - REORG: http: move HTTP rules parsing to http_rules.c
    - CLEANUP: http: remove some leftovers from recent cleanups
    - BUILD: Makefile: add a "make opts" target to simply show the build options
    - BUILD: Makefile: speed up compiler options detection
    - BUG/MINOR: backend: check that the mux installed properly
    - BUG/MEDIUM: h2: check that the connection is still valid at the end of init()
    - BUG/MEDIUM: h2: make h2_stream_new() return an error on memory allocation failure
    - REGTEST/MINOR: compatibility: use unix@ instead of abns@ sockets
    - MINOR: ssl: cleanup old openssl API call
    - MINOR: ssl: generate-certificates for BoringSSL
    - BUG/MEDIUM: buffers: Make sure we don't wrap in ci_insert_line2/b_rep_blk.
    - MEDIUM: ssl: add support for ciphersuites option for TLSv1.3
    - CLEANUP: haproxy: Remove unused variable
    - CLEANUP: h1: Fix debug warnings for h1 headers
    - CLEANUP: stick-tables: Remove unneeded double (()) around conditional clause
    - MEDIUM: task: perform a single tree lookup per run queue batch
    - BUG/MEDIUM: Cur/CumSslConns counters not threadsafe.
    - BUG/MINOR: threads: move declaration of capabilities to config.h
    - OPTIM: tools: optimize my_ffsl() for x86_64
    - BUG/MINOR: h2: null-deref
    - BUG/MINOR: checks: queues null-deref
    - MINOR: connections: Introduce an unsubscribe method.
    - MEDIUM: connections: Change struct wait_list to wait_event.
    - BUG/MEDIUM: h2: Make sure we're not in the send list on flow control.
    - BUG/MEDIUM: mworker: segfault receiving SIGUSR1 followed by SIGTERM.
    - BUG/MEDIUM: stream: Make sure to unsubscribe before si_release_endpoint.
    - MINOR: http: Move comment about some HTTP macros in the right header file
    - MINOR: stats: Add missing include
    - MINOR: http: Export some functions and do cleanup to prepare HTTP refactoring
    - MEDIUM: http: Ignore http-pretend-keepalive option on frontend
    - MEDIUM: http: Ignore http-tunnel option on backend
    - MINOR: http: Use same flag for httpclose and forceclose options
    - MINOR: h1: Add EOH marker during headers parsing
    - MINOR: conn-stream: Add CL_FL_NOT_FIRST flag
    - MINOR: h1: Change the union h1_sl to use indirect strings to store infos
    - MINOR: h1: Add the flag H1_MF_NO_PHDR to not add pseudo-headers during parsing
    - MINOR: log: make sess_log() support sess=NULL
    - MINOR: chunk: add chunk_cpy() and chunk_cat()
    - MEDIUM: h2: stop relying on H2_SS_IDLE / H2_SS_CLOSED
    - CLEANUP: h2: rename h2c_snd_settings() to h2c_send_settings()
    - MINOR: h2: don't try to send data before preface
    - MINOR: h2: unify the mux init function
    - MINOR: h2: retrieve the front proxy from the caller instead of the session
    - MINOR: h2: split h2c_stream_new() into h2s_new() + h2c_frt_stream_new()
    - MINOR: h2: add a new flag to quickly distinguish front vs back connection
    - BUG/MEDIUM: mworker: don't poll on LI_O_INHERITED listeners
    - BUG/MEDIUM: stream: don't crash on out-of-memory
    - BUILD: compiler: add a new statement "__unreachable()"
    - BUILD: lua: silence some compiler warnings about potential null derefs
    - BUILD: ssl: fix null-deref warning in ssl_fc_cipherlist_str sample fetch
    - BUILD: ssl: fix another null-deref warning in ssl_sock_switchctx_cbk()
    - BUILD: stick-table: make sure not to fail on task_new() during initialization
    - BUILD: peers: check allocation error during peers_init_sync()
    - MINOR: tools: add a new function atleast2() to test masks for more than 1 bit
    - MINOR: config: use atleast2() instead of my_popcountl() where relevant
    - MEDIUM: fd/threads: only grab the fd's lock if the FD has more than one thread
    - MAJOR: tasks: create per-thread wait queues
    - OPTIM: tasks: group all tree roots per cache line
    - DOC: Fix a few typos
    - MINOR: pools: allocate most memory pools from an array
    - MINOR: pools: split pool_free() in the lockfree variant
    - MEDIUM: pools: implement a thread-local cache for pool entries
    - BUG/MEDIUM: threads: fix thread_release() at the end of the rendez-vous point
    - Revert "BUILD: lua: silence some compiler warnings about potential null derefs"
    - BUILD: lua: silence some compiler warnings about potential null derefs (#2)
    - MINOR: lua: all functions calling lua_yieldk() may return
    - BUILD: lua: silence some compiler warnings after WILL_LJMP
    - BUILD: Makefile: silence an option conflict warning with clang
    - MINOR: server: Use memcpy() instead of strncpy().
    - CLEANUP: state-file: make the path concatenation code a bit more consistent
    - MINOR: build: Disable -Wstringop-overflow.
    - MINOR: cfgparse: Write 130 as 128 as 0x82 and 0x80.
    - MINOR: peers: use defines instead of enums to appease clang.
    - DOC: fix reference to map files in MAINTAINERS
    - MINOR: fd: centralize poll timeout computation in compute_poll_timeout()
    - MINOR: poller: move time and date computation out of the pollers
    - BUILD: memory: fix pointer declaration for atomic CAS
    - BUILD: Makefile: add USE_RT to pass -lrt for clock_gettime() and friends
    - MINOR: time: add now_mono_time() and now_cpu_time()
    - MEDIUM: time: measure the time stolen by other threads
    - BUILD: memory: fix free_list pointer declaration again for atomic CAS
    - BUILD: compiler: rename __unreachable() to my_unreachable()
    - BUG/MEDIUM: pools: Fix the usage of mmap()) with DEBUG_UAF.
    - BUILD: memory: fix free_list pointer declaration again for atomic CAS
    - BUG/MEDIUM: h2: Close connection if no stream is left an GOAWAY was sent.
    - BUG/MEDIUM: connections: Remove subscription if going in idle mode.
    - BUG/MEDIUM: stream: Make sure polling is right on retry.
    - MINOR: h2: Make sure to return 1 in h2_recv() when needed.
    - MEDIUM: connections: Don't directly mess with the polling from the upper layers.
    - MINOR: streams: Call tasklet_free() after si_release_endpoint().
    - MINOR: connection: Add a SUB_CALL_UNSUBSCRIBE event.
    - MINOR: h2: Don't run tasks that are waiting to send if mux in full.
    - MINOR: ebtree: save 8 bytes in struct eb32sc_node

6 years agoMINOR: ebtree: save 8 bytes in struct eb32sc_node
Willy Tarreau [Sun, 21 Oct 2018 04:52:11 +0000 (06:52 +0200)] 
MINOR: ebtree: save 8 bytes in struct eb32sc_node

There is a 4-bytes hole in this structure after the eb_node and the
last field is 4-bytes as well, resulting in a total of 64 bytes with
8 bytes holes. Just moving the key after the eb_node (like in eb32_node)
fills the hole and reduces the structure's size by 8 bytes.

6 years agoMINOR: h2: Don't run tasks that are waiting to send if mux in full.
Olivier Houchard [Fri, 19 Oct 2018 15:24:29 +0000 (17:24 +0200)] 
MINOR: h2: Don't run tasks that are waiting to send if mux in full.

We wake up all the streams waiting to send data when we have space available
in the mux buffer. Doing so means we probably wake way too many streams,
because after a few the buffer will probably be full instead. So keep a
list of all the streams that are about to send data, and if we detect that
the buffer is full, unschedule the tasks and put the streams back to the
send_list.

6 years agoMINOR: connection: Add a SUB_CALL_UNSUBSCRIBE event.
Olivier Houchard [Thu, 18 Oct 2018 14:26:57 +0000 (16:26 +0200)] 
MINOR: connection: Add a SUB_CALL_UNSUBSCRIBE event.

Add a SUB_CALL_UNSUBSCRIBE event, to let the caller know that the
unsubscribe method should be called before destroyin the object.

6 years agoMINOR: streams: Call tasklet_free() after si_release_endpoint().
Olivier Houchard [Thu, 18 Oct 2018 14:22:02 +0000 (16:22 +0200)] 
MINOR: streams: Call tasklet_free() after si_release_endpoint().

Make sure we call tasklet_free() only after si_release_endpoint(), when the
unsubscribe() method has been called, so that we're sure the mux won't
attempt to access the taslet.

6 years agoMEDIUM: connections: Don't directly mess with the polling from the upper layers.
Olivier Houchard [Wed, 10 Oct 2018 13:46:36 +0000 (15:46 +0200)] 
MEDIUM: connections: Don't directly mess with the polling from the upper layers.

Avoid using conn_xprt_want_send/recv, and totally nuke cs_want_send/recv,
from the upper layers. The polling is now directly handled by the connection
layer, it is activated on subscribe(), and unactivated once we got the event
and we woke the related task.

6 years agoMINOR: h2: Make sure to return 1 in h2_recv() when needed.
Olivier Houchard [Fri, 19 Oct 2018 15:26:49 +0000 (17:26 +0200)] 
MINOR: h2: Make sure to return 1 in h2_recv() when needed.

In h2_recv(), return 1 if we have data available, or if h2_recv_allowed()
failed, to be sure h2_process() is called.
Also don't subscribe if our buffer is full.

6 years agoBUG/MEDIUM: stream: Make sure polling is right on retry.
Olivier Houchard [Sun, 21 Oct 2018 01:18:11 +0000 (03:18 +0200)] 
BUG/MEDIUM: stream: Make sure polling is right on retry.

When retrying to connect to a server, because the previous connection failed,
make sure if we subscribed to the previous connection, the polling flags will
be true for the new fd.

No backport is needed.

6 years agoBUG/MEDIUM: connections: Remove subscription if going in idle mode.
Olivier Houchard [Sat, 20 Oct 2018 22:32:01 +0000 (00:32 +0200)] 
BUG/MEDIUM: connections: Remove subscription if going in idle mode.

Make sure we don't have any subscription when the connection is going in
idle mode, otherwise there's a race condition when the connection is
reused, if there are still old subscriptions, new ones won't be done.

No backport is needed.

6 years agoBUG/MEDIUM: h2: Close connection if no stream is left an GOAWAY was sent.
Olivier Houchard [Sun, 21 Oct 2018 01:01:20 +0000 (03:01 +0200)] 
BUG/MEDIUM: h2: Close connection if no stream is left an GOAWAY was sent.

When we're closing a stream, is there's no stream left and a goaway was sent,
close the connection, there's no reason to keep it open.

[wt: it's likely that this is needed in 1.8 as well, though it's unclear
 how to trigger this issue, some tests are needed]

6 years agoBUILD: memory: fix free_list pointer declaration again for atomic CAS
Olivier Houchard [Sat, 20 Oct 2018 23:52:59 +0000 (01:52 +0200)] 
BUILD: memory: fix free_list pointer declaration again for atomic CAS

Similary to what's been done in 7a6ad88b02d8b74c2488003afb1a7063043ddd2d,
take into account that free_list that free_list is a void **, and so use
a void ** too when attempting to do a CAS.

6 years agoBUG/MEDIUM: pools: Fix the usage of mmap()) with DEBUG_UAF.
Olivier Houchard [Sat, 20 Oct 2018 23:33:11 +0000 (01:33 +0200)] 
BUG/MEDIUM: pools: Fix the usage of mmap()) with DEBUG_UAF.

When mapping memory with mmap(), we should use a fd of -1, not 0. 0 may
work on linux, but it doesn't work on FreeBSD, and probably other OSes.

It would be nice to backport this to 1.8 to help debugging there.

6 years agoBUILD: compiler: rename __unreachable() to my_unreachable()
Willy Tarreau [Sat, 20 Oct 2018 15:45:48 +0000 (17:45 +0200)] 
BUILD: compiler: rename __unreachable() to my_unreachable()

Olivier reported that on FreeBSD __unreachable is already defined
and causes build warnings. Let's rename it then.

6 years agoBUILD: memory: fix free_list pointer declaration again for atomic CAS
Willy Tarreau [Sat, 20 Oct 2018 15:37:38 +0000 (17:37 +0200)] 
BUILD: memory: fix free_list pointer declaration again for atomic CAS

Commit ac6c880 ("BUILD: memory: fix pointer declaration for atomic CAS")
attemtped to fix a build warning affecting the lock-free version of the
pool allocator. But the fix tried to hide the cause instead of addressing
it, thus clang still complains about (void **) not matching (void ***).

The real solution is to declare free_list (void **) and not to use a cast.
Now this builds fine with gcc/clang with and without threads.

No backport is needed.

6 years agoMEDIUM: time: measure the time stolen by other threads
Willy Tarreau [Wed, 17 Oct 2018 17:01:24 +0000 (19:01 +0200)] 
MEDIUM: time: measure the time stolen by other threads

The purpose is to detect if threads or processes are competing for the
same CPU. This can happen when threads are incorrectly bound, or after a
reload if the previous process still has an important activity. With
threads this situation is problematic because a preempted thread holding
a lock will block other ones waiting for this lock to be released.

A first attempt consisted in measuring the cumulated lost time more
precisely but the system's scheduler is smart enough to try to limit the
thread preemption rate by mostly context switching during poll()'s blank
periods, so most of the time lost is not seen. In essence this is good
because it means a thread is not preempted with a lock held, and even
regarding the rendez-vous point it cannot prevent the other ones from
making progress. But still it happens tens to hundreds of times per
second that a thread might be preempted, so it's still possible to detect
that the situation is happening, thus it's interesting to measure and
report its frequency.

Each time we enter the poller, we check the CPU time spent working and
see if we've lost time doing something else. To limit false positives,
we're only interested in losses of 500 microseconds or more (i.e. half
a clock tick on a 1 kHz system). If so, it indicates that some time was
stolen by another thread or process. Note that we purposely store some
sub-millisecond counters so that under heavy traffic with a 1 kHz clock,
it's still possible to measure something without being subject to the
risk of rounding errors (i.e. if exactly 1 ms is stolen it's possible
that the time difference could often be slightly lower).

This counter of lost CPU time slots time is reported in "show activity"
in numbers of milliseconds of CPU lost per second, per 15s, and total
over the process' life. By definition, the per-second counter cannot
report values larger than 1000 per thread per second and the 15s one
will be limited to 15000/s in the worst case, but it's possible that
peak values exceed such thresholds after long pauses.

6 years agoMINOR: time: add now_mono_time() and now_cpu_time()
Willy Tarreau [Wed, 17 Oct 2018 16:59:53 +0000 (18:59 +0200)] 
MINOR: time: add now_mono_time() and now_cpu_time()

These two functions retrieve respectively the monotonic clock time and
the per-thread CPU time when available on the platform, or return zero.
These syscalls may require to link with -lrt on certain libc, which is
enabled in the Makefile with USE_RT=1 (default on Linux systems).

6 years agoBUILD: Makefile: add USE_RT to pass -lrt for clock_gettime() and friends
Willy Tarreau [Thu, 18 Oct 2018 14:28:54 +0000 (16:28 +0200)] 
BUILD: Makefile: add USE_RT to pass -lrt for clock_gettime() and friends

Some code will require clock_gettime() which needs -lrt on most Linux
distros (those with glibc < 2.17). For this reason, this patch introduces
USE_RT to enable -lrt, which is implicitly set for all Linux flavors,
since it's harmless to link with it on more recent ones. Those who know
they can safely get rid of -lrt can remove it using "USE_RT=".

6 years agoBUILD: memory: fix pointer declaration for atomic CAS
Willy Tarreau [Thu, 18 Oct 2018 14:12:28 +0000 (16:12 +0200)] 
BUILD: memory: fix pointer declaration for atomic CAS

The calls to HA_ATOMIC_CAS() on the lockfree version of the pool allocator
were mistakenly done on (void*) for the old value instead of (void **).
While this has no impact on "recent" gcc, it does have one for gcc < 4.7
since the CAS was open coded and it's not possible to assign a temporary
variable of type "void".

No backport is needed, this only affects 1.9.

6 years agoMINOR: poller: move time and date computation out of the pollers
Willy Tarreau [Wed, 17 Oct 2018 12:31:19 +0000 (14:31 +0200)] 
MINOR: poller: move time and date computation out of the pollers

By placing this code into time.h (tv_entering_poll() and tv_leaving_poll())
we can remove the logic from the pollers and prepare for extending this to
offer more accurate time measurements.

6 years agoMINOR: fd: centralize poll timeout computation in compute_poll_timeout()
Willy Tarreau [Wed, 17 Oct 2018 09:25:54 +0000 (11:25 +0200)] 
MINOR: fd: centralize poll timeout computation in compute_poll_timeout()

The 4 pollers all contain the same code used to compute the poll timeout.
This is pointless, let's centralize this into fd.h. This also gets rid of
the useless SCHEDULER_RESOLUTION macro which used to work arond a very old
linux 2.2 bug causing select() to wake up slightly before the timeout.

6 years agoDOC: fix reference to map files in MAINTAINERS
Lukas Tribus [Tue, 16 Oct 2018 23:40:11 +0000 (01:40 +0200)] 
DOC: fix reference to map files in MAINTAINERS

s/maps/map

6 years agoMINOR: peers: use defines instead of enums to appease clang.
Olivier Houchard [Tue, 16 Oct 2018 16:49:26 +0000 (18:49 +0200)] 
MINOR: peers: use defines instead of enums to appease clang.

Clang (rightfully) warns that we're trying to set chars to values >= 128.
Use defines with hex values instead of an enum to address this.

6 years agoMINOR: cfgparse: Write 130 as 128 as 0x82 and 0x80.
Olivier Houchard [Tue, 16 Oct 2018 16:39:38 +0000 (18:39 +0200)] 
MINOR: cfgparse: Write 130 as 128 as 0x82 and 0x80.

Write 130 and 128 as 8x82 and 0x80, to avoid warnings about casting from
int to size. "check_req" should probably be unsigned, but it's hard to do so.

6 years agoMINOR: build: Disable -Wstringop-overflow.
Olivier Houchard [Tue, 16 Oct 2018 16:35:40 +0000 (18:35 +0200)] 
MINOR: build: Disable -Wstringop-overflow.

Disable -Wstringop-overflow, as it gives annoying false positives
with gcc 8.

6 years agoCLEANUP: state-file: make the path concatenation code a bit more consistent
Willy Tarreau [Tue, 16 Oct 2018 17:26:12 +0000 (19:26 +0200)] 
CLEANUP: state-file: make the path concatenation code a bit more consistent

There are as many ways to build the globalfilepathlen variable as branches
in the if/then/else, creating lots of confusion. Address the most obvious
parts, but some polishing definitely is still needed.

6 years agoMINOR: server: Use memcpy() instead of strncpy().
Olivier Houchard [Tue, 16 Oct 2018 16:35:01 +0000 (18:35 +0200)] 
MINOR: server: Use memcpy() instead of strncpy().

Use memcpy instead of strncpy, strncpy buys us nothing, and gcc is being
annoying.

6 years agoBUILD: Makefile: silence an option conflict warning with clang
Willy Tarreau [Tue, 16 Oct 2018 16:11:34 +0000 (18:11 +0200)] 
BUILD: Makefile: silence an option conflict warning with clang

clang complains that -fno-strict-overflow is not used when -fwrapv is
used, which breaks the build when -Werror is used. Let's introduce a
cc-opt-alt function to emit the former only then the latter is not
supported (since it implies the former).

6 years agoBUILD: lua: silence some compiler warnings after WILL_LJMP
Willy Tarreau [Tue, 16 Oct 2018 15:57:36 +0000 (17:57 +0200)] 
BUILD: lua: silence some compiler warnings after WILL_LJMP

These ones are on error paths that are properly handled by luaL_error()
which does a longjmp() but the compiler cannot know it. By adding an
__unreachable() statement in WILL_LJMP(), there is no ambiguity anymore.

This may be backported to 1.8 but these previous patches are needed first :
  - BUILD: compiler: add a new statement "__unreachable()"
  - MINOR: lua: all functions calling lua_yieldk() may return
  - BUILD: lua: silence some compiler warnings about potential null derefs (#2)

6 years agoMINOR: lua: all functions calling lua_yieldk() may return
Willy Tarreau [Tue, 16 Oct 2018 15:52:55 +0000 (17:52 +0200)] 
MINOR: lua: all functions calling lua_yieldk() may return

There was a mistake when tagging functions which always use longjmp and
those which may use it in that all those supposed to call lua_yieldk()
may return without calling longjmp. Thus they must not use WILL_LJMP()
but MAY_LJMP(). It has zero impact on the code emitted as such, but
prevents other fixes from being properly implemented : this was the
cause of the previous failure with the __unreachable() calls.

This may be backported to older versions. It may or may not apply
well depending on the context, though the change simply consists in
replacing "WILL_LJMP(hlua_yieldk" with "MAY_LJMP(hlua_yieldk", and
same with the single call to lua_yieldk() in hlua_yieldk().

6 years agoBUILD: lua: silence some compiler warnings about potential null derefs (#2)
Willy Tarreau [Tue, 16 Oct 2018 15:37:12 +0000 (17:37 +0200)] 
BUILD: lua: silence some compiler warnings about potential null derefs (#2)

Here we make sure that appctx is always taken from the unchecked value
since we know it's an appctx, which explains why it's immediately
dereferenced. A missing test was added to ensure that task_new() does
not return a NULL.

This may be backported to 1.8.

6 years agoRevert "BUILD: lua: silence some compiler warnings about potential null derefs"
Willy Tarreau [Tue, 16 Oct 2018 15:32:55 +0000 (17:32 +0200)] 
Revert "BUILD: lua: silence some compiler warnings about potential null derefs"

This reverts commit f1ffb39b614b0d9654c9450ac6e8c88cfc942784.

It breaks Lua causing some timeouts. Removing the __unreachable() statement
from WILL_LJMP() fixes it. It's very strange and unclear whether it's an
issue with WILL_LJMP() not fullfilling its promise of not returning, if
the code emitted with __unreachable() gets broken, or anything else. Let's
revert this for now.

6 years agoBUG/MEDIUM: threads: fix thread_release() at the end of the rendez-vous point
Willy Tarreau [Tue, 16 Oct 2018 14:11:56 +0000 (16:11 +0200)] 
BUG/MEDIUM: threads: fix thread_release() at the end of the rendez-vous point

There is a bug in this function used to release other threads. It leaves
the current thread marked as harmless. If after this another thread does
a thread_isolate(), but before the first one reaches poll(), the second
thread will believe it's alone while it's not.

This must be backported to 1.8 since the rendez-vous point was merged
into 1.8.14.

6 years agoMEDIUM: pools: implement a thread-local cache for pool entries
Willy Tarreau [Tue, 16 Oct 2018 08:28:54 +0000 (10:28 +0200)] 
MEDIUM: pools: implement a thread-local cache for pool entries

Each thread now keeps the last ~512 kB of freed objects into a local
cache. There are some heuristics involved so that a specific pool cannot
use more than 1/8 of the total cache in number of objects. Tests have
shown that 512 kB is an optimal size on a 24-thread test running on a
dual-socket machine, resulting in an overall 7.5% performance increase
and a cache miss ratio reducing from 19.2 to 17.7%. Anyway it seems
pointless to keep more than an L2 cache, which probably explains why
sizes between 256 and 512 kB are optimal.

Cached objects appear in two lists, one per pool and one LRU to help
with fair eviction. Currently there is no way to check each thread's
cache state nor to flush it. This cache cannot be disabled and is
enabled as soon as the lockless pools are enabled (i.e.: threads are
enabled, no pool debugging is in use and the CPU supports a double word
CAS).

6 years agoMINOR: pools: split pool_free() in the lockfree variant
Willy Tarreau [Tue, 16 Oct 2018 06:55:15 +0000 (08:55 +0200)] 
MINOR: pools: split pool_free() in the lockfree variant

This separates the validity tests from the code committing the object
to the pool, in order to ease insertion of the thread-local cache.

6 years agoMINOR: pools: allocate most memory pools from an array
Willy Tarreau [Tue, 16 Oct 2018 05:58:39 +0000 (07:58 +0200)] 
MINOR: pools: allocate most memory pools from an array

For caching it will be convenient to have indexes associated with pools,
without having to dereference the pool itself. One solution could consist
in replacing all pool pointers with integers but this would limit the
number of allocatable pools. Instead here we allocate the 32 first pools
from a pre-allocated array whose base address is known so that it's trivial
to convert a pool to an index in this array. Pools that cannot fit there
will be allocated normally.

6 years agoDOC: Fix a few typos
Bertrand Jacquin [Sat, 13 Oct 2018 15:06:18 +0000 (16:06 +0100)] 
DOC: Fix a few typos

these are mostly spelling mistakes, some of them might be candidate for
backporting as well.

6 years agoOPTIM: tasks: group all tree roots per cache line
Willy Tarreau [Mon, 15 Oct 2018 14:12:48 +0000 (16:12 +0200)] 
OPTIM: tasks: group all tree roots per cache line

Currently we have per-thread arrays of trees and counts, but these
ones unfortunately share cache lines and are accessed very often. This
patch moves the task-specific stuff into a structure taking a multiple
of a cache line, and has one such per thread. Just doing this has
reduced the cache miss ratio from 19.2% to 18.7% and increased the
12-thread test performance by 3%.

It starts to become visible that we really need a process-wide per-thread
storage area that would cover more than just these parts of the tasks.
The code was arranged so that it's easy to move the pieces elsewhere if
needed.

6 years agoMAJOR: tasks: create per-thread wait queues
Willy Tarreau [Mon, 15 Oct 2018 12:52:21 +0000 (14:52 +0200)] 
MAJOR: tasks: create per-thread wait queues

Now we still have a main contention point with the timers in the main
wait queue, but the vast majority of the tasks are pinned to a single
thread. This patch creates a per-thread wait queue and queues a task
to the local wait queue without any locking if the task is bound to a
single thread (the current one) otherwise to the shared queue using
locking. This significantly reduces contention on the wait queue. A
test with 12 threads showed 11 ms spent in the WQ lock compared to
4.7 seconds in the same test without this change. The cache miss ratio
decreased from 19.7% to 19.2% on the 12-thread test, and its performance
increased by 1.5%.

Another indirect benefit is that the average queue size is divided
by the number of threads, which roughly removes log(nbthreads) levels
in the tree and further speeds up lookups.

6 years agoMEDIUM: fd/threads: only grab the fd's lock if the FD has more than one thread
Willy Tarreau [Mon, 15 Oct 2018 07:44:46 +0000 (09:44 +0200)] 
MEDIUM: fd/threads: only grab the fd's lock if the FD has more than one thread

The vast majority of FDs are only seen by one thread. Currently the lock
on FDs costs a lot because it's touched often, though there should be very
little contention. This patch ensures that the lock is only grabbed if the
FD is shared by more than one thread, since otherwise the situation is safe.
Doing so resulted in a 15% performance boost on a 12-threads test.

6 years agoMINOR: config: use atleast2() instead of my_popcountl() where relevant
Willy Tarreau [Mon, 15 Oct 2018 07:37:03 +0000 (09:37 +0200)] 
MINOR: config: use atleast2() instead of my_popcountl() where relevant

Quite often we used my_popcountl() just to check for > 1 bit set. Now
we have an easier solution, let's use it.

6 years agoMINOR: tools: add a new function atleast2() to test masks for more than 1 bit
Willy Tarreau [Mon, 15 Oct 2018 07:33:41 +0000 (09:33 +0200)] 
MINOR: tools: add a new function atleast2() to test masks for more than 1 bit

For threads it's common to have to check if a mask contains more than
one bit set. Let's have this "atleast2()" function report this.

6 years agoBUILD: peers: check allocation error during peers_init_sync()
Willy Tarreau [Mon, 15 Oct 2018 09:18:03 +0000 (11:18 +0200)] 
BUILD: peers: check allocation error during peers_init_sync()

peers_init_sync() doesn't check task_new()'s return value and doesn't
return any result to indicate success or failure. Let's make it return
an int and check it from the caller.

This can be backported as far as 1.6.

6 years agoBUILD: stick-table: make sure not to fail on task_new() during initialization
Willy Tarreau [Mon, 15 Oct 2018 09:12:15 +0000 (11:12 +0200)] 
BUILD: stick-table: make sure not to fail on task_new() during initialization

Gcc reports a potential null-deref error in the stick-table init code.
While not critical there, it's trivial to fix. This check has been
missing since 1.4 so this fix can be backported to all supported versions.

6 years agoBUILD: ssl: fix another null-deref warning in ssl_sock_switchctx_cbk()
Willy Tarreau [Mon, 15 Oct 2018 11:20:07 +0000 (13:20 +0200)] 
BUILD: ssl: fix another null-deref warning in ssl_sock_switchctx_cbk()

This null-deref cannot happen either as there necesarily is a listener
where this function is called. Let's use __objt_listener() to address
this.

This may be backported to 1.8.

6 years agoBUILD: ssl: fix null-deref warning in ssl_fc_cipherlist_str sample fetch
Willy Tarreau [Mon, 15 Oct 2018 09:01:59 +0000 (11:01 +0200)] 
BUILD: ssl: fix null-deref warning in ssl_fc_cipherlist_str sample fetch

Gcc 6.4 detects a potential null-deref warning in smp_fetch_ssl_fc_cl_str().
This one is not real since already addressed a few lines above. Let's use
__objt_conn() instead of objt_conn() to avoid the extra test that confuses
it.

This could be backported to 1.8.

6 years agoBUILD: lua: silence some compiler warnings about potential null derefs
Willy Tarreau [Mon, 15 Oct 2018 09:55:18 +0000 (11:55 +0200)] 
BUILD: lua: silence some compiler warnings about potential null derefs

These ones are on error paths that are properly handled by luaL_error()
which does a longjmp() but the compiler cannot know it. By adding an
__unreachable() statement in WILL_LJMP(), there is no ambiguity anymore.

This may be backported to 1.8 but the previous patch (BUILD: compiler:
add a new statement "__unreachable()") is needed for this.

6 years agoBUILD: compiler: add a new statement "__unreachable()"
Willy Tarreau [Mon, 15 Oct 2018 09:53:34 +0000 (11:53 +0200)] 
BUILD: compiler: add a new statement "__unreachable()"

This statement is used as a hint for the compiler so that it knows that
the location where it's placed cannot be reached. It will mostly be used
after longjmp() or equivalent statements that deal with error processing
and that the compiler doesn't know will not return on certain conditions,
so that it doesn't complain about null dereferences on error paths.

6 years agoBUG/MEDIUM: stream: don't crash on out-of-memory
Willy Tarreau [Mon, 15 Oct 2018 09:08:55 +0000 (11:08 +0200)] 
BUG/MEDIUM: stream: don't crash on out-of-memory

In case pool_alloc() fails in stream_new(), we try to detach the stream
from the list before it has been added, dereferencing a NULL. In order
to fix it, simply move the LIST_DEL call upwards.

This must be backported to 1.8.

6 years agoBUG/MEDIUM: mworker: don't poll on LI_O_INHERITED listeners
William Lallemand [Fri, 12 Oct 2018 08:39:54 +0000 (10:39 +0200)] 
BUG/MEDIUM: mworker: don't poll on LI_O_INHERITED listeners

The listeners with the LI_O_INHERITED flag were deleted but not unbound
which is a problem since we have a polling in the master.

This patch unbind every listeners which are not require for the master,
but does not close the FD of those that have a LI_O_INHERITED flag.

6 years agoMINOR: h2: add a new flag to quickly distinguish front vs back connection
Willy Tarreau [Wed, 3 Oct 2018 11:56:38 +0000 (13:56 +0200)] 
MINOR: h2: add a new flag to quickly distinguish front vs back connection

We will need to know if a mux was created for a front or a back
connection and once it's established it's much harder, so let's
introduce H2_CF_IS_BACK for this.

6 years agoMINOR: h2: split h2c_stream_new() into h2s_new() + h2c_frt_stream_new()
Willy Tarreau [Wed, 3 Oct 2018 16:53:55 +0000 (18:53 +0200)] 
MINOR: h2: split h2c_stream_new() into h2s_new() + h2c_frt_stream_new()

For backend connections we'll have to initialize streams but not allocate
conn_streams since they'll already be there. Thus this patch splits the
h2c_stream_new() function into one dedicated to allocation of a new stream
and another one supposed to attach this stream to an existing frontend
connection.

6 years agoMINOR: h2: retrieve the front proxy from the caller instead of the session
Willy Tarreau [Wed, 3 Oct 2018 08:33:02 +0000 (10:33 +0200)] 
MINOR: h2: retrieve the front proxy from the caller instead of the session

Till now in order to figure the timeouts, we used to retrieve the proxy
from the session's owner, but the new API provides it so it's better to
simply take it from the caller at init time. We take this opportunity to
store the pointer to the proxy into the h2 connection so that we can
reuse it later when needed.

6 years agoMINOR: h2: unify the mux init function
Willy Tarreau [Wed, 3 Oct 2018 11:52:41 +0000 (13:52 +0200)] 
MINOR: h2: unify the mux init function

The init function was split into the mux init and the front init, but it
appears that most of the code will be common between the two sides when
implementing the backend init. Thus let's simply make this a unique
h2_init() function.

6 years agoMINOR: h2: don't try to send data before preface
Willy Tarreau [Mon, 8 Oct 2018 07:43:03 +0000 (09:43 +0200)] 
MINOR: h2: don't try to send data before preface

h2_snd_buf() must not accept to send data if the preface was not yet
received nor sent. At the moment it doesn't happen but it can with
server-side H2.

6 years agoCLEANUP: h2: rename h2c_snd_settings() to h2c_send_settings()
Willy Tarreau [Mon, 8 Oct 2018 05:13:08 +0000 (07:13 +0200)] 
CLEANUP: h2: rename h2c_snd_settings() to h2c_send_settings()

It's the only function not called h2c_send_<something>() and it took me
a while to find it.

6 years agoMEDIUM: h2: stop relying on H2_SS_IDLE / H2_SS_CLOSED
Willy Tarreau [Fri, 5 Oct 2018 08:16:37 +0000 (10:16 +0200)] 
MEDIUM: h2: stop relying on H2_SS_IDLE / H2_SS_CLOSED

At a few places we check these states to detect if a stream has valid
data/errcode or is one of the two dummy streams (idle or closed). It
will become problematic for outgoing streams as it will not be possible
to report errors for example since the stream will switch from IDLE
state only after sending a HEADERS frame.

There is a safer solution consisting in checking the stream ID, which
may only be zero in the dummy streams. This patch changes the test to
only rely on the stream ID.

6 years agoMINOR: chunk: add chunk_cpy() and chunk_cat()
Willy Tarreau [Mon, 8 Oct 2018 05:34:25 +0000 (07:34 +0200)] 
MINOR: chunk: add chunk_cpy() and chunk_cat()

Sometimes we need to concatenate constant chunks to existing ones, but
no function currently exists to do this easily, hence these two new ones.

6 years agoMINOR: log: make sess_log() support sess=NULL
Willy Tarreau [Fri, 5 Oct 2018 08:22:27 +0000 (10:22 +0200)] 
MINOR: log: make sess_log() support sess=NULL

At many places in muxes we'll have to add tests to check if the
connection is front or back before deciding to log. Instead let's
centralize this test in sess_log() to simply do nothing when sess=NULL.

6 years agoMINOR: h1: Add the flag H1_MF_NO_PHDR to not add pseudo-headers during parsing
Christopher Faulet [Mon, 8 Oct 2018 13:50:15 +0000 (15:50 +0200)] 
MINOR: h1: Add the flag H1_MF_NO_PHDR to not add pseudo-headers during parsing

Some pseudo-headers are added during the headers parsing, mainly for the mux
H2. With this flag, it is possible to not add them. This avoid some boring
filtering in the mux H1.

6 years agoMINOR: h1: Change the union h1_sl to use indirect strings to store infos
Christopher Faulet [Mon, 8 Oct 2018 13:34:02 +0000 (15:34 +0200)] 
MINOR: h1: Change the union h1_sl to use indirect strings to store infos

Instead of using offsets relating to the parsed buffer to store start line
infos, we now use indirect strings. So now, these infos remain valid only if the
origin buffer remains untouched. But it's not a real problem because this union
is used during the parsing and never stored to a later use.

6 years agoMINOR: conn-stream: Add CL_FL_NOT_FIRST flag
Christopher Faulet [Mon, 1 Oct 2018 10:10:13 +0000 (12:10 +0200)] 
MINOR: conn-stream: Add CL_FL_NOT_FIRST flag

This flags will be used by multiplexers to warn a conn-stream (and, by
transitivity, a stream) it is not the first one created by the mux. It will help
mux H1 to handle keep-alive connections.

6 years agoMINOR: h1: Add EOH marker during headers parsing
Christopher Faulet [Tue, 25 Sep 2018 11:59:46 +0000 (13:59 +0200)] 
MINOR: h1: Add EOH marker during headers parsing

When headers parsing ends, a pseudo header with an empty name and an empty value
is added to the array of parsed headers to mark its end. It is convenient to
loop on this array, but not really useful if we want remove the last header or
add a new one, because we don't really know where is the last CRLF (the empty
line ending the headers block). So now, instead the name of this pseudo header
points on this last CRLF. Its length is still 0 and its value is still empty, so
loops on the array remains unchanged.

6 years agoMINOR: http: Use same flag for httpclose and forceclose options
Christopher Faulet [Fri, 21 Sep 2018 14:26:19 +0000 (16:26 +0200)] 
MINOR: http: Use same flag for httpclose and forceclose options

Since keep-alive mode is the default mode, the passive close has disappeared,
and in the code, httpclose and forceclose options are handled the same way:
connections with the client and the server are closed as soon as the request and
the response are received and missing "Connection: close" header is added in
each direction.

So to make things clearer, forceclose is now an alias for httpclose. And
httpclose is explicitly an active close. So the old passive close does not exist
anymore. Internally, the flag PR_O_HTTP_PCL has been removed and PR_O_HTTP_FCL
has been replaced by PR_O_HTTP_CLO. In HTTP analyzers, the checks done to find
the right mode to use, depending on proxies options and "Connection: " header
value, have been simplified.

This should only be a cleanup and no changes are expected.

6 years agoMEDIUM: http: Ignore http-tunnel option on backend
Christopher Faulet [Fri, 21 Sep 2018 08:42:19 +0000 (10:42 +0200)] 
MEDIUM: http: Ignore http-tunnel option on backend

This option is frontends specific, so there is no reason to support it on
backends. So now, it is ignored if it is set on a backend and a warning is
emitted during the startup. The change is quite trivial, but the commit is
tagged as MEDIUM because it is a small breakage with previous versions and
configurations using this options could emit a warning now.

6 years agoMEDIUM: http: Ignore http-pretend-keepalive option on frontend
Christopher Faulet [Fri, 21 Sep 2018 08:25:19 +0000 (10:25 +0200)] 
MEDIUM: http: Ignore http-pretend-keepalive option on frontend

This option is backends specific, so there is no reason to support it on
frontends. So now, it is ignored if it is set on a frontend and a warning is
emitted during the startup. The change is quite trivial, but the commit is
tagged as MEDIUM because it is a small breakage with previous versions and
configurations using this options could emit a warning now.

6 years agoMINOR: http: Export some functions and do cleanup to prepare HTTP refactoring
Christopher Faulet [Wed, 3 Oct 2018 13:17:28 +0000 (15:17 +0200)] 
MINOR: http: Export some functions and do cleanup to prepare HTTP refactoring

To ease the refactoring, the function "http_header_add_tail" have been
remove. Now, "http_header_add_tail2" is always used. And the function
"capture_headers" have been renamed into "http_capture_headers". Finally, some
functions have been exported.

6 years agoMINOR: stats: Add missing include
Christopher Faulet [Wed, 3 Oct 2018 14:11:20 +0000 (16:11 +0200)] 
MINOR: stats: Add missing include

"proto/stats.h" must include "types/stats.h".

6 years agoMINOR: http: Move comment about some HTTP macros in the right header file
Christopher Faulet [Wed, 3 Oct 2018 12:15:28 +0000 (14:15 +0200)] 
MINOR: http: Move comment about some HTTP macros in the right header file

HTTP_FLG_* and HTTP_IS_* were moved from "proto/proto_http.h" to "common/http.h"
but the associated comment was forgotten during the move.

This is 1.9-specific and should not be backported.

6 years agoBUG/MEDIUM: stream: Make sure to unsubscribe before si_release_endpoint.
Olivier Houchard [Thu, 11 Oct 2018 15:09:14 +0000 (17:09 +0200)] 
BUG/MEDIUM: stream: Make sure to unsubscribe before si_release_endpoint.

Make sure we unsubscribe from events before si_release_endpoint destroys
the conn_stream, or it will be never called. To do so, move the call to
unsubscribe to si_release_endpoint() directly.

This is 1.9-specific and shouldn't be backported.

6 years agoBUG/MEDIUM: mworker: segfault receiving SIGUSR1 followed by SIGTERM.
Emeric Brun [Thu, 11 Oct 2018 13:27:07 +0000 (15:27 +0200)] 
BUG/MEDIUM: mworker: segfault receiving SIGUSR1 followed by SIGTERM.

This bug appeared only if nbthread > 1. Handling the pipe with the
master, multiple threads of the same worker could process the deinit().

In addition, deinit() was called while some other threads were still
performing some tasks.

This patch assign the handler of the pipe with master to only the first
thread and removes the call to deinit() before exiting with an error.

This patch should be backported in v1.8.

6 years agoBUG/MEDIUM: h2: Make sure we're not in the send list on flow control.
Olivier Houchard [Wed, 10 Oct 2018 16:51:00 +0000 (18:51 +0200)] 
BUG/MEDIUM: h2: Make sure we're not in the send list on flow control.

If we can't send data for a stream because of its flow control, make sure
not to put it in the send_list, until the flow control lets it send again.

This is specific to 1.9, and should not be backported.

6 years agoMEDIUM: connections: Change struct wait_list to wait_event.
Olivier Houchard [Wed, 10 Oct 2018 16:25:41 +0000 (18:25 +0200)] 
MEDIUM: connections: Change struct wait_list to wait_event.

When subscribing, we don't need to provide a list element, only the h2 mux
needs it. So instead, Add a list element to struct h2s, and use it when a
list is needed.
This forces us to use the unsubscribe method, since we can't just unsubscribe
by using LIST_DEL anymore.
This patch is larger than it should be because it includes some renaming.

6 years agoMINOR: connections: Introduce an unsubscribe method.
Olivier Houchard [Fri, 28 Sep 2018 15:57:58 +0000 (17:57 +0200)] 
MINOR: connections: Introduce an unsubscribe method.

As we don't know how subscriptions are handled, we can't just assume we can
use LIST_DEL() to unsubscribe, so introduce a new method to mux and connections
to do so.

6 years agoBUG/MINOR: checks: queues null-deref
mildis [Tue, 2 Oct 2018 14:46:34 +0000 (16:46 +0200)] 
BUG/MINOR: checks: queues null-deref

queues can be null if calloc() failed.
Bypass free* calls when calloc did fail.

6 years agoBUG/MINOR: h2: null-deref
mildis [Tue, 2 Oct 2018 14:44:18 +0000 (16:44 +0200)] 
BUG/MINOR: h2: null-deref

h2c can be null if pool_alloc() failed.
Bypass tasklet_free and pool_free if pool_alloc did fail.

6 years agoOPTIM: tools: optimize my_ffsl() for x86_64
Willy Tarreau [Wed, 10 Oct 2018 17:05:56 +0000 (19:05 +0200)] 
OPTIM: tools: optimize my_ffsl() for x86_64

This call is now used quite a bit in the fd cache, to decide which cache
to add/remove the fd to/from, when waking up a task for a single thread
in __task_wakeup(), in fd_cant_recv() and in fd_process_cached_events(),
and we can replace it with a single instruction, removing ~30 instructions
and ~80 bytes from the inner loop of some of these functions.

In addition the test for zero value was replaced with a comment saying
that it is illegal and leads to an undefined behaviour. The code does
not make use of this useless case today.

6 years agoBUG/MINOR: threads: move declaration of capabilities to config.h
Willy Tarreau [Wed, 10 Oct 2018 16:29:23 +0000 (18:29 +0200)] 
BUG/MINOR: threads: move declaration of capabilities to config.h

In commit f161d0f51 ("BUG/MINOR: pools/threads: don't ignore DEBUG_UAF
on double-word CAS capable archs") I moved some defines and accidently
messed up with lockfree pools. The problem is that the HA_HAVE_CAS_DW
macro is not defined anymore where the CONFIG_HAP_LOCKLESS_POOLS macro
is set, so this fix implicitly disabled lockfree pools.

This patch fixes this by moving the capabilities definition to config.h
(probably that we'd benefit from having an "arch.h" file to declare the
capabilities offered by the architecture). In a test on a 12-core machine,
we used to measure 19s spent in the pool lock for 1M requests without
this patch, and 0 with it so that's definitely a net saving.

No backport is required, this is only for 1.9.

6 years agoBUG/MEDIUM: Cur/CumSslConns counters not threadsafe.
Emeric Brun [Wed, 10 Oct 2018 12:51:02 +0000 (14:51 +0200)] 
BUG/MEDIUM: Cur/CumSslConns counters not threadsafe.

CurSslConns inc/dec operations are not threadsafe. The unsigned CurSslConns
counter can wrap to a negative value. So we could notice connection rejects
because of MaxSslConns limit artificially exceeded.

CumSslConns inc operation are also not threadsafe so we could miss
some connections and show inconsistenties values compared to CumConns.

This fix should be backported to v1.8.