]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
6 years agoMEDIUM: mworker: does not create the CLI proxy when no listener
William Lallemand [Tue, 6 Nov 2018 16:37:12 +0000 (17:37 +0100)] 
MEDIUM: mworker: does not create the CLI proxy when no listener

Does not create the CLI proxy if no -S argument was specified. It
prevents a warning that says that the MASTER proxy does not have any
bind option.

6 years agoMINOR: cli: can't connect to the target CLI
William Lallemand [Tue, 6 Nov 2018 16:37:11 +0000 (17:37 +0100)] 
MINOR: cli: can't connect to the target CLI

Return an error and quit if the CLI proxy is not able to connect to a
target.

6 years agoMINOR: cli: show the number of reload in 'show proc'
William Lallemand [Tue, 6 Nov 2018 16:37:10 +0000 (17:37 +0100)] 
MINOR: cli: show the number of reload in 'show proc'

Displays the number of reload in the life of each worker.

6 years agoMINOR: stats: report the number of currently connected peers
Willy Tarreau [Mon, 5 Nov 2018 16:12:27 +0000 (17:12 +0100)] 
MINOR: stats: report the number of currently connected peers

The active peers output indicates both the number of established peers
connections and the number of peers connection attempts. The new counter
"ConnectedPeers" also indicates the number of currently connected peers.
This helps detect that some peers cannot be reached for example. It's
worth mentioning that this value changes over time because unused peers
are often disconnected and reconnected. Most of the time it should be
equal to ActivePeers.

6 years agoMINOR: stats: report the number of active peers in "show info"
Willy Tarreau [Mon, 5 Nov 2018 15:31:22 +0000 (16:31 +0100)] 
MINOR: stats: report the number of active peers in "show info"

Peers are the last type of activity which can maintain a job present, so
it's important to report that such an entity is still active to explain
why the job count may be higher than zero. Here by "ActivePeers" we report
peers sessions, which include both established connections and outgoing
connection attempts.

6 years agoMINOR: stats: report the number of active jobs and listeners in "show info"
Willy Tarreau [Mon, 5 Nov 2018 13:38:13 +0000 (14:38 +0100)] 
MINOR: stats: report the number of active jobs and listeners in "show info"

When an haproxy process doesn't stop after a reload, it's because it
still has some active "jobs", which mainly are active sessions, listeners,
peers or other specific activities. Sometimes it's difficult to troubleshoot
the cause of these issues (which generally are the result of a bug) only
because some indicators are missing.

This patch add the number of listeners, the number of jobs, and the stopping
status to the output of "show info". This way it becomes a bit easier to try
to narrow down the cause of such an issue should it happen. A typical use
case is to connect to the CLI before reloading, then issuing the "show info"
command to see what happens. In the normal situation, stopping should equal
1, jobs should equal 1 (meaning only the CLI is still active) and listeners
should equal zero.

The patch is so trivial that it could make sense to backport it to 1.8 in
order to help with troubleshooting.

6 years agoBUG/MINOR: tasks: make sure wakeup events are properly reported to subscribers
Willy Tarreau [Mon, 5 Nov 2018 14:09:47 +0000 (15:09 +0100)] 
BUG/MINOR: tasks: make sure wakeup events are properly reported to subscribers

The tasks API was changed in 1.9-dev1 with commit 9f6af3322 ("MINOR: tasks:
Change the task API so that the callback takes 3 arguments."), causing the
task's state not to be usable anymore and to have been replaced with an
explicit argument in the callee. The task's state doesn't contain any trace
of the wakeup cause anymore. But there were two places where the old task's
state remained in use :
  - sessions, used to more accurately report timeouts in logs when seeing
    TASK_WOKEN_TIMEOUT ;
  - peers, used to finish resynchronization when seeing TASK_WOKEN_SIGNAL

This commit fixes both occurrences by making sure we don't access task->state
directly (should we rename it by the way ?).

No backport is needed.

6 years agoBUG/MAJOR: stream-int: don't call si_cs_recv() in stream_int_chk_rcv_conn()
Willy Tarreau [Tue, 30 Oct 2018 10:01:08 +0000 (11:01 +0100)] 
BUG/MAJOR: stream-int: don't call si_cs_recv() in stream_int_chk_rcv_conn()

This one causes some events to be lost. It has already been tested in
an experimental branch but was not merged until being certain it was
needed. Fred figured that requesting /?k=1&s=447392 from httpterm through
haproxy-master was enough to stall the transfer.

No backport is needed, this only affects 1.9-dev5.

6 years agoDOC: split the http-response actions in their own section
Cyril Bonté [Tue, 16 Oct 2018 22:14:51 +0000 (00:14 +0200)] 
DOC: split the http-response actions in their own section

Similarly to the "http-request" actions, this is an attempt to make the
documentation easier to read.

6 years agoDOC: split the http-request actions in their own section
Cyril Bonté [Tue, 16 Oct 2018 22:14:50 +0000 (00:14 +0200)] 
DOC: split the http-request actions in their own section

Since http-request was first introduced, more and more actions have been
added over time. This makes the "http-request" difficult to read and some
actions were forgotten in the list.

This is an attempt to make the documenation cleaner. In future steps, it
would be great to provide at least one example for each action.

6 years agoMEDIUM: auth/threads: make use of crypt_r() on systems supporting it
Willy Tarreau [Mon, 29 Oct 2018 18:16:27 +0000 (19:16 +0100)] 
MEDIUM: auth/threads: make use of crypt_r() on systems supporting it

On systems where crypt_r() is available, prefer it over a locked crypt().
This improves performance especially on very slow crypto algorithms.

6 years agoMINOR: compat: automatically detect support for crypt_r()
Willy Tarreau [Mon, 29 Oct 2018 18:14:14 +0000 (19:14 +0100)] 
MINOR: compat: automatically detect support for crypt_r()

glibc >= 2.2 and FreeBSD >= 12.0 support crypt_r(), let's detect this
and set a macro HA_HAVE_CRYPT_R for this.

6 years agoBUG/MEDIUM: auth/threads: use of crypt() is not thread-safe
Willy Tarreau [Mon, 29 Oct 2018 17:02:54 +0000 (18:02 +0100)] 
BUG/MEDIUM: auth/threads: use of crypt() is not thread-safe

It was reported here that authentication may fail when threads are
enabled :

    https://bugzilla.redhat.com/show_bug.cgi?id=1643941

While I couldn't reproduce the issue, it's obvious that there is a
problem with the use of the non-reentrant crypt() function there.
On Linux systems there's crypt_r() but not on the vast majority of
other ones. Thus a first approach consists in placing a lock around
this crypt() call. Another patch may relax it when crypt_r() is
available.

This fix must be backported to 1.8. Thanks to Ryan O'Hara for the
quick notification.

6 years agoBUG/MINOR: cli: forward the whole command on master CLI
William Lallemand [Mon, 29 Oct 2018 16:14:00 +0000 (17:14 +0100)] 
BUG/MINOR: cli: forward the whole command on master CLI

A bug occurs when the CLI proxy of the master received a command which
is prefixed by some spaces but without a routing prefix (@).
In this case the pcli_parse_request() was returning a wrong number of
data to forward.

The response analyzer was called twice and the prompt displayed twice.

6 years agoBUG/MEDIUM: tools: fix direction of my_ffsl()
Willy Tarreau [Mon, 29 Oct 2018 15:09:57 +0000 (16:09 +0100)] 
BUG/MEDIUM: tools: fix direction of my_ffsl()

Commit 27346b01a ("OPTIM: tools: optimize my_ffsl() for x86_64") optimized
my_ffsl() for intensive use cases in the scheduler, but as half of the times
I got it wrong so it counted bits the reverse way. It doesn't matter for the
scheduler nor fd cache but it broke cpu-map with threads which heavily relies
on proper ordering.

We should probably consider dropping support for gcc < 3.4 and switching
to builtins for these ones, though often they are as ambiguous.

No backport is needed.

6 years ago[RELEASE] Released version 1.9-dev5 v1.9-dev5
Willy Tarreau [Sun, 28 Oct 2018 19:39:31 +0000 (20:39 +0100)] 
[RELEASE] Released version 1.9-dev5

Released version 1.9-dev5 with the following main changes :
    - BUILD: Makefile: add the new ERR variable to force -Werror
    - MINOR: freq_ctr: add swrate_add_scaled() to work with large samples
    - MINOR: stream_interface: Avoid calling si_cs_send/recv if not needed.
    - CLEANUP: http: Remove the unused function http_find_header
    - MINOR: h1: Export some functions parsing the value of some HTTP headers
    - BUG/MEDIUM: stream-int: don't set SI_FL_WAIT_ROOM on CF_READ_DONTWAIT
    - MINOR: proxy: add a new option "http-use-htx"
    - BUG/MEDIUM: pools: fix the minimum allocation size
    - MINOR: shctx: Shared objects block by block allocation.
    - MINOR: cache: Larger HTTP objects caching.
    - MINOR: shctx: Add a maximum object size parameter.
    - MINOR: cache: Add "max-object-size" option.
    - DOC: Update about the cache support for big objects.
    - BUG/MINOR: cache: Crashes with "total-max-size" > 2047(MB).
    - BUG/MINOR: cache: Wrong usage of shctx_init().
    - BUG/MINOR: ssl: Wrong usage of shctx_init().
    - MINOR: cache: Avoid usage of atoi() when parsing "max-object-size".
    - MINOR: shctx: Change max. object size type to unsigned int.
    - DOC: cache: Missing information about "total-max-size" and "max-object-size"
    - CLEANUP: tools: fix misleading comment above function LIM2A
    - MEDIUM: channel: merge back flags CF_WRITE_PARTIAL and CF_WRITE_EVENT
    - BUG/MINOR: only mark connections private if NTLM is detected
    - BUG/MINOR: only auto-prefer last server if lb-alg is non-deterministic
    - MINOR: stream: don't prune variables if the list is empty
    - MINOR: stream-int: add si_alloc_ibuf() to ease input buffer allocation
    - MEDIUM: stream-int: replace channel_alloc_buffer() with si_alloc_ibuf() everywhere
    - MEDIUM: stream: always call si_cs_recv() after a failed buffer allocation
    - MEDIUM: stream: don't try to send first in process_stream()
    - MEDIUM: stream-int: make si_update() synchronize flag changes before the I/O
    - MEDIUM: stream-int: call si_cs_process() in stream_int_update_conn
    - MINOR: stream-int: don't needlessly call tasklet_wakeup() in stream_int_chk_snd_conn()
    - MINOR: stream-int: make stream_int_notify() not wake the tasklet up
    - MINOR: stream-int: don't needlessly call si_cs_send() in si_cs_process()
    - MINOR: mworker: number of reload in the life of a worker
    - MEDIUM: mworker: each worker socketpair is a CLI listener
    - REORG: mworker: move struct mworker_proc to global.h
    - MINOR: server: export new_server() function
    - MEDIUM: mworker: move proc_list gen before proxies startup
    - MEDIUM: mworker: add proc_list in global.h
    - MEDIUM: mworker: proxy for the master CLI
    - MEDIUM: mworker: create CLI listeners from argv[]
    - MEDIUM: cli: disable some keywords in the master
    - MEDIUM: mworker: find the server ptr using a CLI prefix
    - MEDIUM: cli: 'show proc' displays processus
    - MEDIUM: cli: implement 'mode cli' proxy analyzers
    - MINOR: cli: displays sockpair@ in "show cli sockets"
    - MEDIUM: cli: enable "show cli sockets" for the master
    - MINOR: cli: put @master @<relative pid> @!<pid> in the help
    - MEDIUM: listeners: set O_CLOEXEC on the accepted FDs
    - MEDIUM: mworker: stop the master proxy in the workers
    - MEDIUM: channel: reorder the channel analyzers for the cli
    - MEDIUM: cli: write a prompt for the CLI proxy of the master
    - MINOR: cli: helper to write an response message and close
    - MINOR: cache: Add "Age" header.
    - REGTEST: make the IP+port logging test more reliable
    - BUG/MINOR: memory: make the thread-local cache allocator set the debugging link
    - BUG/MAJOR: http: http_txn_get_path() may deference an inexisting buffer
    - BUG/MINOR: backend: assign the wait list after the error check

6 years agoBUG/MINOR: backend: assign the wait list after the error check
Willy Tarreau [Sun, 28 Oct 2018 19:36:00 +0000 (20:36 +0100)] 
BUG/MINOR: backend: assign the wait list after the error check

Commit 85b73e9 ("BUG/MEDIUM: stream: Make sure polling is right on retry.")
introduced a possible null dereference on the error path detected by gcc-7.
Let's simply assign srv_conn after checking the error and not before.

No backport is needed.

6 years agoBUG/MAJOR: http: http_txn_get_path() may deference an inexisting buffer
Willy Tarreau [Sun, 28 Oct 2018 19:13:12 +0000 (20:13 +0100)] 
BUG/MAJOR: http: http_txn_get_path() may deference an inexisting buffer

When the "path" sample fetch function is called without any path, the
function doesn't check that the request buffer is allocated. While this
doesn't happen with the request during processing, it can definitely
happen when mistakenly trying to reference a path from the response
since the request channel is not allocated anymore.

It's certain that this bug was emphasized by the buffer changes that
went in 1.9 and the HTTP refactoring, but at first glance, 1.8 doesn't
seem 100% safe either so it's possible that older version are affected
as well.

Thanks to PiBa-NL for reporting this bug with a reproducer.

6 years agoBUG/MINOR: memory: make the thread-local cache allocator set the debugging link
Willy Tarreau [Sun, 28 Oct 2018 19:09:12 +0000 (20:09 +0100)] 
BUG/MINOR: memory: make the thread-local cache allocator set the debugging link

When building with DEBUG_MEMORY_POOLS, an element returned from the
cache would not have its pool link initialized unless it's allocated
using pool_alloc(). This is problematic for buffer allocators which
use pool_alloc_dirty(), as freeing this object will make the code
think it was allocated from another pool. This patch does two things :
  - make __pool_get_from_cache() set the link
  - remove the extra initialization from pool_alloc() since it's always
    done in either __pool_get_first() or __pool_refill_alloc()

This patch is marked MINOR since it only affects code explicitly built
for debugging. No backport is needed.

6 years agoREGTEST: make the IP+port logging test more reliable
Willy Tarreau [Sun, 28 Oct 2018 18:19:48 +0000 (19:19 +0100)] 
REGTEST: make the IP+port logging test more reliable

On my machine, test log/b00000.vtc fails ~9/10 times. Apparently, the
connection is often marked as reset before the timeout strikes, so the
log shows "CD" flags instead of "cD". This fix does two things :
  1) shorten the client timeout to 1 millisecond instead of 5
  2) accept both "cD" and "CD" as valid termination states since the
     purpose is to validate the source address and port, and not the
     status itself.

6 years agoMINOR: cache: Add "Age" header.
Frédéric Lécaille [Fri, 26 Oct 2018 12:29:22 +0000 (14:29 +0200)] 
MINOR: cache: Add "Age" header.

This patch makes the cache capable of adding an "Age" header as defined by
rfc7234.

During the storage of new HTTP objects we memorize ->eoh value and
the value of the "Age" header coming from the origin server.
These information may then be reused to return the cached HTTP objects
with a new "Age" header.

May be backported to 1.8.

6 years agoMINOR: cli: helper to write an response message and close
William Lallemand [Fri, 26 Oct 2018 12:47:48 +0000 (14:47 +0200)] 
MINOR: cli: helper to write an response message and close

pcli_reply_and_close() writes a message to the client and close the
connection. To be used only in the CLI proxy.

6 years agoMEDIUM: cli: write a prompt for the CLI proxy of the master
William Lallemand [Fri, 26 Oct 2018 12:47:47 +0000 (14:47 +0200)] 
MEDIUM: cli: write a prompt for the CLI proxy of the master

Write a prompt with the PID of the target or master.
It's always activated for now.

Example:
    1234>
    master>

6 years agoMEDIUM: channel: reorder the channel analyzers for the cli
William Lallemand [Fri, 26 Oct 2018 12:47:46 +0000 (14:47 +0200)] 
MEDIUM: channel: reorder the channel analyzers for the cli

Reorder the channel analyzers so the CLI analyzers are defined before
the XFER_DATA ones.

6 years agoMEDIUM: mworker: stop the master proxy in the workers
William Lallemand [Fri, 26 Oct 2018 12:47:45 +0000 (14:47 +0200)] 
MEDIUM: mworker: stop the master proxy in the workers

The master proxy which handles the CLI should not be used or shown in
the stats of the workers. This proxy is now disabled after the fork.

6 years agoMEDIUM: listeners: set O_CLOEXEC on the accepted FDs
William Lallemand [Fri, 26 Oct 2018 12:47:44 +0000 (14:47 +0200)] 
MEDIUM: listeners: set O_CLOEXEC on the accepted FDs

Set the O_CLOEXEC flag on the accept, useful to avoid an FD leak in the
master process, since it reexecutes itself during a reload

6 years agoMINOR: cli: put @master @<relative pid> @!<pid> in the help
William Lallemand [Fri, 26 Oct 2018 12:47:43 +0000 (14:47 +0200)] 
MINOR: cli: put @master @<relative pid> @!<pid> in the help

Add help for the prefix command of the CLI. These help only displays
from the CLI of the master.

6 years agoMEDIUM: cli: enable "show cli sockets" for the master
William Lallemand [Fri, 26 Oct 2018 12:47:42 +0000 (14:47 +0200)] 
MEDIUM: cli: enable "show cli sockets" for the master

Enable the keyword on the master CLI.

6 years agoMINOR: cli: displays sockpair@ in "show cli sockets"
William Lallemand [Fri, 26 Oct 2018 12:47:41 +0000 (14:47 +0200)] 
MINOR: cli: displays sockpair@ in "show cli sockets"

The 'show cli sockets' was not handling the sockpairs, it now displays
the fd of the socket and also show the unknown protocols.

6 years agoMEDIUM: cli: implement 'mode cli' proxy analyzers
William Lallemand [Fri, 26 Oct 2018 12:47:40 +0000 (14:47 +0200)] 
MEDIUM: cli: implement 'mode cli' proxy analyzers

This patch implements analysers for parsing the CLI and extra features
for the master's CLI.

For each command (sent alone, or separated by ; or \n) the request
analyser will determine to which server it should send the request.

The 'mode cli' proxy is able to parse a prefix for each command which is
used to select the apropriate server. The prefix start by @ and is
followed by "master", the PID preceded by ! or the relative PID. (e.g.
@master, @1, @!1234). The servers are not round-robined anymore.

The command is sent with a SHUTW which force the server to close the
connection after sending its response. However the proxy allows a
keepalive connection on the client side and does not close.

The response analyser does not do much stuff, it only reinits the
connection when it received a close from the server, and forward the
response. It does not analyze the response data.
The only guarantee of the end of the response is the close of the
server, we can't rely on the double \n since it's not send by every
command.

This could be reimplemented later as a filter.

6 years agoMEDIUM: cli: 'show proc' displays processus
William Lallemand [Fri, 26 Oct 2018 12:47:39 +0000 (14:47 +0200)] 
MEDIUM: cli: 'show proc' displays processus

This patch implements a command which displays the current processes.

It only works in the CLI of the master.

6 years agoMEDIUM: mworker: find the server ptr using a CLI prefix
William Lallemand [Fri, 26 Oct 2018 12:47:38 +0000 (14:47 +0200)] 
MEDIUM: mworker: find the server ptr using a CLI prefix

Add a struct server pointer in the mworker_proc struct so we can easily
use it as a target for the mworker proxy.

pcli_prefix_to_pid() is used to find the right PID of the worker
when using a prefix in the CLI. (@master, @#<relative pid> , @<pid>)

pcli_pid_to_server() is used to find the right target server for the
CLI proxy.

6 years agoMEDIUM: cli: disable some keywords in the master
William Lallemand [Fri, 26 Oct 2018 12:47:37 +0000 (14:47 +0200)] 
MEDIUM: cli: disable some keywords in the master

The master process does not need all the keywords of the cli, add 2
flags to chose which keyword to use.

It might be useful to activate some of them in a debug mode later...

6 years agoMEDIUM: mworker: create CLI listeners from argv[]
William Lallemand [Fri, 26 Oct 2018 12:47:36 +0000 (14:47 +0200)] 
MEDIUM: mworker: create CLI listeners from argv[]

This patch introduces mworker_cli_proxy_new_listener() which allows the
creation of new listeners for the CLI proxy.

Using this function it is possible to create new listeners from the
program arguments with -Sa <unix_socket>. It is allowed to create
multiple listeners with several -Sa.

6 years agoMEDIUM: mworker: proxy for the master CLI
William Lallemand [Fri, 26 Oct 2018 12:47:35 +0000 (14:47 +0200)] 
MEDIUM: mworker: proxy for the master CLI

This patch implements a listen proxy within the master. It uses the
sockpair of all the workers as servers.

In the current state of the code, the proxy is only doing round robin on
the CLI of the workers. A CLI mode will be needed to know to which CLI
send the requests.

6 years agoMEDIUM: mworker: add proc_list in global.h
William Lallemand [Fri, 26 Oct 2018 12:47:34 +0000 (14:47 +0200)] 
MEDIUM: mworker: add proc_list in global.h

Add the process list in types/global.h so it could be accessed from
anywhere.

6 years agoMEDIUM: mworker: move proc_list gen before proxies startup
William Lallemand [Fri, 26 Oct 2018 12:47:33 +0000 (14:47 +0200)] 
MEDIUM: mworker: move proc_list gen before proxies startup

We need to generate the process list before starting the proxies,
because it will be used to create a proxy in the master

6 years agoMINOR: server: export new_server() function
William Lallemand [Fri, 26 Oct 2018 12:47:32 +0000 (14:47 +0200)] 
MINOR: server: export new_server() function

The new_server() function will be useful to create a proxy for the
master-worker.

6 years agoREORG: mworker: move struct mworker_proc to global.h
William Lallemand [Fri, 26 Oct 2018 12:47:31 +0000 (14:47 +0200)] 
REORG: mworker: move struct mworker_proc to global.h

Move the definition of the mworker_proc structure in types/global.h.

6 years agoMEDIUM: mworker: each worker socketpair is a CLI listener
William Lallemand [Fri, 26 Oct 2018 12:47:30 +0000 (14:47 +0200)] 
MEDIUM: mworker: each worker socketpair is a CLI listener

The init code of the mworker_proc structs has been moved before the
init of the listeners.

Each socketpair is now connected to a CLI within the workers, which
allows the master to access their CLI.

The inherited flag of the worker side socketpair is removed so the
socket can be closed in the master.

6 years agoMINOR: mworker: number of reload in the life of a worker
William Lallemand [Fri, 26 Oct 2018 12:47:29 +0000 (14:47 +0200)] 
MINOR: mworker: number of reload in the life of a worker

This patch adds a field in the mworker_proc structure which contains how
much time the master reloaded during the life of a worker.

6 years agoMINOR: stream-int: don't needlessly call si_cs_send() in si_cs_process()
Willy Tarreau [Thu, 25 Oct 2018 12:02:47 +0000 (14:02 +0200)] 
MINOR: stream-int: don't needlessly call si_cs_send() in si_cs_process()

There's a call there to si_cs_send() while we're supposed to come from
si_cs_io_cb() which has just done it. But in fact we can also come here
as a lower layer callback from ->wake() after a connection is established.
Since most of the time we'll end up here with either no data in the buffer
or a blocked output, let's simply check if we're already susbcribed to send
events before calling si_cs_send().

6 years agoMINOR: stream-int: make stream_int_notify() not wake the tasklet up
Willy Tarreau [Thu, 25 Oct 2018 11:55:20 +0000 (13:55 +0200)] 
MINOR: stream-int: make stream_int_notify() not wake the tasklet up

stream_int_notify() is I/O agnostic and should not wake up the tasklet,
it's up to si_cs_process() to do that, just like si_applet_wake_cb()
does it for the applet.

6 years agoMINOR: stream-int: don't needlessly call tasklet_wakeup() in stream_int_chk_snd_conn()
Willy Tarreau [Thu, 25 Oct 2018 11:49:49 +0000 (13:49 +0200)] 
MINOR: stream-int: don't needlessly call tasklet_wakeup() in stream_int_chk_snd_conn()

This one was added by commit 53216e7db ("MEDIUM: connections: Don't
directly mess with the polling from the upper layers.") after the
removal of the conditional cs_want_send() call. But after analysis
it turned out that it's not needed since the si_cs_send() call will
either succeed or subscribe.

6 years agoMEDIUM: stream-int: call si_cs_process() in stream_int_update_conn
Willy Tarreau [Sun, 28 Oct 2018 12:32:08 +0000 (13:32 +0100)] 
MEDIUM: stream-int: call si_cs_process() in stream_int_update_conn

Calling si_cs_send() alone is always dangerous because it can result
in the loss of an event if it manages to empty the buffer. Indeed, in
this case it's critical to call si_chk_rcv() on the opposite stream-int.
Given that si_cs_process() takes care of all this, let's call it instead.
All this code could possibly be refined soon to avoid redoing the whole
stream_int_notify() and do it only after a send(), but at the moment it's
not important.

6 years agoMEDIUM: stream-int: make si_update() synchronize flag changes before the I/O
Willy Tarreau [Thu, 25 Oct 2018 09:06:57 +0000 (11:06 +0200)] 
MEDIUM: stream-int: make si_update() synchronize flag changes before the I/O

With the new synchronous si_cs_send() at the end of process_stream(),
we're seeing re-appear the I/O layer specific part of the stream interface
which is supposed to deal with I/O event subscription. The only difference
is that now we subscribe to I/Os only after having attempted (and failed)
them.

This patch brings a cleanup in this by reintroducing stream_int_update_conn()
with the send code from process_stream(). However this alone would not be
enough because the flags which are cleared afterwards would result in the
loss of the possible events (write events only at the moment). So the flags
clearing and stream-int state updates are also performed inside si_update()
between the generic code and the I/O specific code. This definitely makes
sense as after this call we can simply check again for channel and SI flag
changes and decide to loop once again or not.

6 years agoMEDIUM: stream: don't try to send first in process_stream()
Willy Tarreau [Thu, 25 Oct 2018 08:42:39 +0000 (10:42 +0200)] 
MEDIUM: stream: don't try to send first in process_stream()

The rationale here is that we should never need to try to send() at the
beginning of process_stream() because :
  - if something was pending, it's very unlikely that it was unblocked
    and not sent just between the last poll() and the wakeup instant.
  - if something pending was recently sent, then we don't have anything
    to send anymore.

So at first glance it doesn't seem like there could be any valid case
where trying to send before entering the function brings any benefit.

6 years agoMEDIUM: stream: always call si_cs_recv() after a failed buffer allocation
Willy Tarreau [Thu, 25 Oct 2018 08:28:27 +0000 (10:28 +0200)] 
MEDIUM: stream: always call si_cs_recv() after a failed buffer allocation

If a buffer allocation failed, we have SI_FL_WAIT_ROOM set and c_size(buf)
being zero. It's the only moment where we have a new opportunity to try to
allocate this buffer. However we don't want to waste our time trying this
if both are non-null since it indicates missing room without any changed
condition.

6 years agoMEDIUM: stream-int: replace channel_alloc_buffer() with si_alloc_ibuf() everywhere
Willy Tarreau [Thu, 25 Oct 2018 08:21:41 +0000 (10:21 +0200)] 
MEDIUM: stream-int: replace channel_alloc_buffer() with si_alloc_ibuf() everywhere

Well that's only 3 places (applet.c, stream_interface.c, hlua.c). This
ensures we always clear SI_FL_WAIT_ROOM before setting it on failure,
so that it is granted that SI_FL_WAIT_ROOM always indicates a lack of
room for doing an operation, including the inability to allocate a
buffer for this.

6 years agoMINOR: stream-int: add si_alloc_ibuf() to ease input buffer allocation
Willy Tarreau [Thu, 25 Oct 2018 08:16:07 +0000 (10:16 +0200)] 
MINOR: stream-int: add si_alloc_ibuf() to ease input buffer allocation

This will supersed channel_alloc_buffer() while relying on it. It will
automatically adjust SI_FL_WAIT_ROOM on the stream-int depending on
success or failure to allocate this buffer.

It's worth noting that it could make sense to also set SI_FL_WANT_PUT
each time we do this to further simplify the code at user places such
as applets, but it would possibly not be easy to clean this flag
everywhere an rx operation stops.

6 years agoMINOR: stream: don't prune variables if the list is empty
Willy Tarreau [Sun, 28 Oct 2018 12:44:36 +0000 (13:44 +0100)] 
MINOR: stream: don't prune variables if the list is empty

The vars_prune() and vars_init() functions involve locking while most of
the time there is no variable at all in streams nor sessions. Let's check
for emptiness before calling these functions. Simply doing this has
increased the multithreaded performance from 1.5 to 5% depending on the
workload.

6 years agoBUG/MINOR: only auto-prefer last server if lb-alg is non-deterministic
Lukas Tribus [Sat, 27 Oct 2018 18:07:40 +0000 (20:07 +0200)] 
BUG/MINOR: only auto-prefer last server if lb-alg is non-deterministic

While "option prefer-last-server" only applies to non-deterministic load
balancing algorithms, 401/407 responses actually caused haproxy to prefer
the last server unconditionally.

As this breaks deterministic load balancing algorithms like uri, this
patch applies the same condition here.

Should be backported to 1.8 (together with "BUG/MINOR: only mark
connections private if NTLM is detected").

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.