]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
3 months agoMEDIUM: acme: generate the account file when not found
William Lallemand [Mon, 28 Apr 2025 15:40:26 +0000 (17:40 +0200)] 
MEDIUM: acme: generate the account file when not found

Generate the private key on the account file when the file does not
exists. This generate a private key of the type and parameters
configured in the acme section.

3 months agoMINOR: acme: failure when no directory is specified
William Lallemand [Mon, 28 Apr 2025 15:37:21 +0000 (17:37 +0200)] 
MINOR: acme: failure when no directory is specified

The "directory" parameter of the acme section is mandatory. This patch
exits with an alert when this parameter is not found.

3 months agoMINOR: acme: separate the code generating private keys
William Lallemand [Mon, 28 Apr 2025 14:27:45 +0000 (16:27 +0200)] 
MINOR: acme: separate the code generating private keys

acme_EVP_PKEY_gen() generates private keys of specified <keytype>,
<curves> and <bits>. Only RSA and EC are supported for now.

3 months agoBUG/MINOR: ssl/acme: free EVP_PKEY upon error
William Lallemand [Mon, 28 Apr 2025 14:33:48 +0000 (16:33 +0200)] 
BUG/MINOR: ssl/acme: free EVP_PKEY upon error

Free the EPV_PKEY upon error when the X509_REQ generation failed.

No backport needed.

3 months agoMEDIUM: thread: set DEBUG_THREAD to 1 by default
Willy Tarreau [Mon, 28 Apr 2025 13:57:26 +0000 (15:57 +0200)] 
MEDIUM: thread: set DEBUG_THREAD to 1 by default

Setting DEBUG_THREAD to 1 allows recording the lock history for each
thread. Tests have shown that (as predicted) the cost of updating a
single thread-local variable is not perceptible in the noise, especially
when compared to the cost of obtaining a lock. Since this can provide
useful value when debugging deadlocks, let's enable it by default when
threads are enabled.

3 months agoMINOR: threads/cli: display the lock history on "show threads"
Willy Tarreau [Mon, 28 Apr 2025 13:19:35 +0000 (15:19 +0200)] 
MINOR: threads/cli: display the lock history on "show threads"

This will display the lock labels and modes for each non-empty step
at the end of "show threads" when these are defined. This allows to
emit up to the last 8 locking operation for each thread on 64 bit
machines.

3 months agoMEDIUM: threads: keep history of taken locks with DEBUG_THREAD > 0
Willy Tarreau [Mon, 28 Apr 2025 07:42:58 +0000 (09:42 +0200)] 
MEDIUM: threads: keep history of taken locks with DEBUG_THREAD > 0

by only storing a word in each thread context, we can keep the history
of all taken/dropped locks by label. This is expected to be very cheap
and to permit to store up to 8 consecutive lock operations in 64 bits.
That should significantly help detect recursive locks as well as figure
what thread was likely to hinder another one waiting for a lock.

For now we only store the final state of the lock, we don't store the
attempt to get it. It's just a matter of space since we already need
4 ops (rd,sk,wr,un) which take 2 bits, leaving max 64 labels. We're
already around 45. We could also multiply by 5 and still keep 8 bits
total per lock, that would limit us to 51 locks max. It seems that
most of the time if we get a watchdog panic, anyway the victim thread
will be perfectly located so that we don't need a specific value for
this. Another benefit is that we perform a single memory write per
lock.

3 months agoMINOR: threads: turn the full lock debugging to DEBUG_THREAD=2
Willy Tarreau [Mon, 28 Apr 2025 07:05:02 +0000 (09:05 +0200)] 
MINOR: threads: turn the full lock debugging to DEBUG_THREAD=2

At level 1 it now does nothing. This is reserved for some subsequent
patches which will implement lighter debugging.

3 months agoMINOR: threads: prepare DEBUG_THREAD to receive more values
Willy Tarreau [Mon, 28 Apr 2025 07:00:00 +0000 (09:00 +0200)] 
MINOR: threads: prepare DEBUG_THREAD to receive more values

We now default the value to zero and make sure all tests properly take
care of values above zero. This is in preparation for supporting several
degrees of debugging.

3 months agoBUILD: leastconn: fix build warning when building without threads on old machines
Willy Tarreau [Mon, 28 Apr 2025 14:48:42 +0000 (16:48 +0200)] 
BUILD: leastconn: fix build warning when building without threads on old machines

Machines lacking CAS8B/DWCAS and emit a warning in lb_fwlc.c without
threads due to declaration ordering. Let's just move the variable
declaration into the block that uses it as a last variable. No
backport is needed.

3 months agoBUILD: acme: use my_strndup() instead of strndup()
Willy Tarreau [Mon, 28 Apr 2025 14:35:24 +0000 (16:35 +0200)] 
BUILD: acme: use my_strndup() instead of strndup()

Not all systems have strndup(), that's why we have our "my_strndup()",
so let's make use of it here. This fixes the build on Solaris 10. No
backport is needed.

3 months agoMINOR: promex: expose ST_I_PX_RATE (current_session_rate)
Aurelien DARRAGON [Mon, 28 Apr 2025 10:19:36 +0000 (12:19 +0200)] 
MINOR: promex: expose ST_I_PX_RATE (current_session_rate)

It has been requested to have the current_session_rate exposed at the
frontend level. For now only the per-process value was exposed
(ST_I_INF_SESS_RATE).

Thanks to the work done lately to merge promex and stat_cols_px[]
array, let's simply defined an .alt_name for the ST_I_PX_RATE metric in
order to have promex exposing it as current_session_rate for relevant
contexts.

3 months agoDOC: config: clarify log-forward "host" option
Aurelien DARRAGON [Mon, 28 Apr 2025 10:09:45 +0000 (12:09 +0200)] 
DOC: config: clarify log-forward "host" option

log-forward "host" option may be confusing because we often mention the
host field when talking about syslog RFC3164 or RFC5424 messages, but
neither rfc actually define "host" field. In fact, everywhere we used
"host field" we actually meant "hostname field" as documented in RFC5424.
This was a language abuse on our side.

In this patch we replace "host" with "hostname" where relevant in the
documentation to prevent confusion.

Thanks to Nick Ramirez for having reported the issue.

3 months agoDOC: config: fix ACME paragraph rendering issue
Aurelien DARRAGON [Mon, 28 Apr 2025 09:30:01 +0000 (11:30 +0200)] 
DOC: config: fix ACME paragraph rendering issue

Nick Ramirez reported that the ACME paragraph (3.13) caused a rendering
issue where simple text was rendered as a directive. This was caused
by the use of unescaped <name> which confuses dconv.

Let's escape <name> by putting quotes around it to prevent the rendering
issue.

No backport needed.

3 months agoMINOR: ssl/cli: add a '-t' option to 'show ssl sni'
William Lallemand [Mon, 28 Apr 2025 09:35:11 +0000 (11:35 +0200)] 
MINOR: ssl/cli: add a '-t' option to 'show ssl sni'

Add a -t option to 'show ssl sni', allowing to add an offset to the
current date so it would allow to check which certificates are expired
after a certain period of time.

3 months agoBUG/MAJOR: listeners: transfer connection accounting when switching listeners
Willy Tarreau [Fri, 25 Apr 2025 16:32:02 +0000 (18:32 +0200)] 
BUG/MAJOR: listeners: transfer connection accounting when switching listeners

Since we made it possible for a bind_conf to listen to multiple thread
groups with shards in 2.8 with commit 9d360604bd ("MEDIUM: listener:
rework thread assignment to consider all groups"), the per-listener
connection count was not properly transferred to the target listener
with the connection when switching to another thread group. This results
in one listener possibly reaching high values and another one possibly
reaching negative values. Usually it's not visible, unless a maxconn is
set on the bind_conf, in which case comparisons will quickly put an end
to the willingness to accept new connections.

This problem only happens when thread groups are enabled, and it seems
very hard to trigger it normally, it only impacts sockets having a single
shard, hence currently the CLI (or any conf with "bind ... shards 1"),
where it can be reproduced with a config having a very low "maxconn" on
the stats socket directive (here, 4), and issuing a few tens of
socat <<< "show activity" in parallel, or sending HTTP connections to a
single-shared listener. Very quickly, haproxy stops accepting connections
and eats CPU in the poller which tries to get its connections accepted.

A BUG_ON(l->nbconn<0) after HA_ATOMIC_DEC() in listener_release() also
helps spotting them better.

Many thanks to Christian Ruppert who once again provided a very accurate
report in GH #2951 with the required data permitting this analysis.

This fix must be backported to 2.8.

3 months agoBUG/MAJOR: tasklets: Make sure he tasklet can't run twice
Olivier Houchard [Fri, 25 Apr 2025 10:17:07 +0000 (12:17 +0200)] 
BUG/MAJOR: tasklets: Make sure he tasklet can't run twice

tasklets were originally designed to alway run on only one thread, so it
was not possible to have it run on 2 threads concurrently.
The API has been extended so that another thread may wake the tasklet,
the idea was still that we wanted to have it run on one thread only.
However, the way it's been done meant that unless a tasklet was bound to
a specific tid with tasklet_set_tid(), or we explicitely used
tasklet_wakeup_on() to specify the thread for the target to run on, it
would be scheduled to run on the current thread.
This is in fact a desirable feature. There is however a race condition
in which the tasklet would be scheduled on a thread, while it is running
on another. This could lead to the same tasklet to run on multiple
threads, which we do not want.
To fix this, just do what we already do for regular tasks, set the
"TASK_RUNNING" flag, and when it's time to execute the tasklet, wait
until that flag is gone.
Only one case has been found in the current code, where the tasklet
could run on different threads depending on who wakes it up, in the
leastconn load balancer, since commit
627280e15f03755b8f59f0191cd6d6bcad5afeb3.
It should not be a problem in practice, as the function called can be
called concurrently.
If a bug is eventually found in relation to this problem, and this patch
should be backported, the following patches should be backported too :
MEDIUM: quic: Make sure we return the tasklet from quic_accept_run
MEDIUM: quic: Make sure we return NULL in quic_conn_app_io_cb if needed
MEDIUM: quic: Make sure we return the tasklet from qcc_io_cb
MEDIUM: mux_fcgi: Make sure we return the tasklet from fcgi_deferred_shut
MEDIUM: listener: Make sure w ereturn the tasklet from accept_queue_process
MEDIUM: checks: Make sure we return the tasklet from srv_chk_io_cb

3 months agoMEDIUM: quic: Make sure we return the tasklet from quic_accept_run
Olivier Houchard [Fri, 25 Apr 2025 11:03:29 +0000 (13:03 +0200)] 
MEDIUM: quic: Make sure we return the tasklet from quic_accept_run

In quic_accept_run, return the tasklet to tell the scheduler the tasklet
is still alive, it is not yet needed, but will be soon.

3 months agoMEDIUM: quic: Make sure we return NULL in quic_conn_app_io_cb if needed
Olivier Houchard [Fri, 25 Apr 2025 11:02:47 +0000 (13:02 +0200)] 
MEDIUM: quic: Make sure we return NULL in quic_conn_app_io_cb if needed

In quic_conn_app_io_cb, make sure we return NULL if the tasklet has been
destroyed, so that the scheduler knows. It is not yet needed, but will
be soon.

3 months agoMEDIUM: quic: Make sure we return the tasklet from qcc_io_cb
Olivier Houchard [Fri, 25 Apr 2025 11:01:58 +0000 (13:01 +0200)] 
MEDIUM: quic: Make sure we return the tasklet from qcc_io_cb

In qcc_io_cb, return the tasklet to tell the scheduler the tasklet is
still alive, it is not yet needed, but will be soon.

3 months agoMEDIUM: mux_fcgi: Make sure we return the tasklet from fcgi_deferred_shut
Olivier Houchard [Fri, 25 Apr 2025 11:01:15 +0000 (13:01 +0200)] 
MEDIUM: mux_fcgi: Make sure we return the tasklet from fcgi_deferred_shut

In fcgi_deferred_shut, return the tasklet to tell the scheduler the
tasklet is still alive, it is not yet needed, but will be soon.

3 months agoMEDIUM: listener: Make sure w ereturn the tasklet from accept_queue_process
Olivier Houchard [Fri, 25 Apr 2025 11:00:34 +0000 (13:00 +0200)] 
MEDIUM: listener: Make sure w ereturn the tasklet from accept_queue_process

In accept_queue_process, return the tasklet to tell the scheduler the
tasklet is still alive, it is not yet needed, but will be soon.

3 months agoMEDIUM: checks: Make sure we return the tasklet from srv_chk_io_cb
Olivier Houchard [Fri, 25 Apr 2025 10:59:37 +0000 (12:59 +0200)] 
MEDIUM: checks: Make sure we return the tasklet from srv_chk_io_cb

In srv_chk_io_cb, return the tasklet to tell the scheduler the tasklet
is still alive, it is not yet needed, but will be soon.

3 months ago[RELEASE] Released version 3.2-dev12 v3.2-dev12
Willy Tarreau [Fri, 25 Apr 2025 08:19:03 +0000 (10:19 +0200)] 
[RELEASE] Released version 3.2-dev12

Released version 3.2-dev12 with the following main changes :
    - BUG/MINOR: quic: do not crash on CRYPTO ncbuf alloc failure
    - BUG/MINOR: proxy: always detach a proxy from the names tree on free()
    - CLEANUP: proxy: detach the name node in proxy_free_common() instead
    - CLEANUP: Slightly reorder some proxy option flags to free slots
    - MINOR: proxy: Add options to drop HTTP trailers during message forwarding
    - MINOR: h1-htx: Skip C-L and T-E headers for 1xx and 204 messages during parsing
    - MINOR: mux-h1: Keep custom "Content-Length: 0" header in 1xx and 204 messages
    - MINOR: hlua/h1: Use http_parse_cont_len_header() to parse content-length value
    - CLEANUP: h1: Remove now useless h1_parse_cont_len_header() function
    - BUG/MEDIUM: mux-spop: Respect the negociated max-frame-size value to send frames
    - MINOR: http-act: Add 'pause' action to temporarily suspend the message analysis
    - MINOR: acme/cli: add the 'acme renew' command to the help message
    - MINOR: httpclient: add an "https" log-format
    - MEDIUM: acme: use a customized proxy
    - MEDIUM: acme: rename "uri" into "directory"
    - MEDIUM: acme: rename "account" into "account-key"
    - MINOR: stick-table: use a separate lock label for updates
    - MINOR: h3: simplify h3_rcv_buf return path
    - BUG/MINOR: mux-quic: fix possible infinite loop during decoding
    - BUG/MINOR: mux-quic: do not decode if conn in error
    - BUG/MINOR: cli: Issue an error when too many args are passed for a command
    - MINOR: cli: Use a full prompt command for bidir connections with workers
    - MAJOR: cli: Refacor parsing and execution of pipelined commands
    - MINOR: cli: Rename some CLI applet states to reflect recent refactoring
    - CLEANUP: applet: Update st0/st1 comment in appctx structure
    - BUG/MINOR: hlua: Fix I/O handler of lua CLI commands to not rely on the SC
    - BUG/MINOR: ring: Fix I/O handler of "show event" command to not rely on the SC
    - MINOR: cli/applet: Move appctx fields only used by the CLI in a private context
    - MINOR: cache: Add a pointer on the cache in the cache applet context
    - MINOR: hlua: Use the applet name in error messages for lua services
    - MINOR: applet: Save the "use-service" rule in the stream to init a service applet
    - CLEANUP: applet: Remove unsued rule pointer in appctx structure
    - BUG/MINOR: master/cli: properly trim the '@@' process name in error messages
    - MEDIUM: resolvers: add global "dns-accept-family" directive
    - MINOR: resolvers: add command-line argument -4 to force IPv4-only DNS
    - MINOR: sock-inet: detect apparent IPv6 connectivity
    - MINOR: resolvers: add "dns-accept-family auto" to rely on detected IPv6
    - MEDIUM: acme: use Retry-After value for retries
    - MEDIUM: acme: reset the remaining retries
    - MEDIUM: acme: better error/retry management of the challenge checks
    - BUG/MEDIUM: cli: Handle applet shutdown when waiting for a command line
    - Revert "BUG/MINOR: master/cli: properly trim the '@@' process name in error messages"
    - BUG/MINOR: master/cli: only parse the '@@' prefix on complete lines
    - MINOR: resolvers: use the runtime IPv6 status instead of boot time one

3 months agoMINOR: resolvers: use the runtime IPv6 status instead of boot time one
Willy Tarreau [Fri, 25 Apr 2025 07:26:44 +0000 (09:26 +0200)] 
MINOR: resolvers: use the runtime IPv6 status instead of boot time one

On systems where the network is not reachable at boot time (certain HA
systems for example, or dynamically addressed test machines), we'll want
to be able to periodically revalidate the IPv6 reachability status. The
current code makes it complicated because it sets the config bits once
for all at boot time. This commit changes this so that the config bits
are not changed, but instead we rely on a static inline function that
relies on sock_inet6_seems_reachable for every test (really cheap). This
also removes the now unneeded resolvers late init code.

This variable for now is still set at boot time but this will ease the
transition later, as the resolvers code is now ready for this.

3 months agoBUG/MINOR: master/cli: only parse the '@@' prefix on complete lines
Willy Tarreau [Fri, 25 Apr 2025 06:40:57 +0000 (08:40 +0200)] 
BUG/MINOR: master/cli: only parse the '@@' prefix on complete lines

The new adhoc parser for the '@@' prefix forgot to require the presence
of the LF character marking the end of the line. This is the reason why
entering incomplete commands would display garbage, because the line was
expected to have its LF character replaced with a zero.

The problem is well illustrated by using socat in raw mode:

   socat /tmp/master.sock STDIO,raw,echo=0

then entering "@@1 show info" one character at a time would error just
after the second "@". The command must take care to report an incomplete
line and wait for more data in such a case.

3 months agoRevert "BUG/MINOR: master/cli: properly trim the '@@' process name in error messages"
Willy Tarreau [Fri, 25 Apr 2025 06:43:48 +0000 (08:43 +0200)] 
Revert "BUG/MINOR: master/cli: properly trim the '@@' process name in error messages"

This reverts commit 0e94339eaf1c8423132debb6b1b485d8bb1bb7da.

This patch was in fact fixing the symptom, not the cause. The root cause
of the problem is that the parser was processing an incomplete line when
looking for '@@'. When the LF is present, this problem does not exist
as it's properly replaced with a zero. This can be verified using socat
in raw mode:

  socat /tmp/master.sock STDIO,raw,echo=0

Then entering "@@1 show info" one character at a time will immediately
fail on "@@" without going further. A subsequent patch will fix this.
No backport is needed.

3 months agoBUG/MEDIUM: cli: Handle applet shutdown when waiting for a command line
Christopher Faulet [Thu, 24 Apr 2025 16:54:32 +0000 (18:54 +0200)] 
BUG/MEDIUM: cli: Handle applet shutdown when waiting for a command line

When the CLI applet was refactord in the commit 20ec1de21 ("MAJOR: cli:
Refacor parsing and execution of pipelined commands"), a regression was
introduced. The applet shutdown was not longer handled when the applet was
waiting for the next command line. It is especially visible when a client
timeout occurred because the client connexion is no longer closed.

To fix the issue, the test on the SE_FL_SHW flag was reintroduced in
CLI_ST_PARSE_CMDLINE state, but only is there is no pending input data.

It is a 3.2-specific issue. No backport needed.

3 months agoMEDIUM: acme: better error/retry management of the challenge checks
William Lallemand [Thu, 24 Apr 2025 17:58:56 +0000 (19:58 +0200)] 
MEDIUM: acme: better error/retry management of the challenge checks

When the ACME task is checking for the status of the challenge, it would
only succeed or retry upon failure.

However that's not the best way to do it, ACME objects contain an
"status" field which could have a final status or a in progress status,
so we need to be able to retry.

This patch adds an acme_ret enum which contains OK, RETRY and FAIL.

In the case of the CHKCHALLENGE, the ACME could return a "pending" or a
"processing" status, which basically need to be rechecked later with the
RETRY. However a "invalid" or "valid" status is final and will return
either a FAIL or a OK.

So instead of retrying in any case, the "invalid" status will ends the
task with an error.

3 months agoMEDIUM: acme: reset the remaining retries
William Lallemand [Thu, 24 Apr 2025 15:50:29 +0000 (17:50 +0200)] 
MEDIUM: acme: reset the remaining retries

When a request succeed, reset the remaining retries to the default
ACME_RETRY value (3 by default).

3 months agoMEDIUM: acme: use Retry-After value for retries
William Lallemand [Thu, 24 Apr 2025 15:31:51 +0000 (17:31 +0200)] 
MEDIUM: acme: use Retry-After value for retries

Parse the Retry-After header in response and store it in order to use
the value as the next delay for the next retry, fallback to 3s if the
value couldn't be parse or does not exist.

3 months agoMINOR: resolvers: add "dns-accept-family auto" to rely on detected IPv6
Willy Tarreau [Thu, 24 Apr 2025 15:18:06 +0000 (17:18 +0200)] 
MINOR: resolvers: add "dns-accept-family auto" to rely on detected IPv6

Instead of always having to force IPv4 or IPv6, let's now also offer
"auto" which will only enable IPv6 if the system has a default gateway
for it. This means that properly configured dual-stack systems will
default to "ipv4,ipv6" while those lacking a gateway will only use
"ipv4". Note that no real connectivity test is performed, so firewalled
systems may still get it wrong and might prefer to rely on a manual
"ipv4" assignment.

3 months agoMINOR: sock-inet: detect apparent IPv6 connectivity
Willy Tarreau [Thu, 24 Apr 2025 15:05:14 +0000 (17:05 +0200)] 
MINOR: sock-inet: detect apparent IPv6 connectivity

In order to ease dual-stack deployments, we could at least try to
check if ipv6 seems to be reachable. For this we're adding a test
based on a UDP connect (no traffic) on port 53 to the base of
public addresses (2001::) and see if the connect() is permitted,
indicating that the routing table knows how to reach it, or fails.
Based on this result we're setting a global variable that other
subsystems might use to preset their defaults.

3 months agoMINOR: resolvers: add command-line argument -4 to force IPv4-only DNS
Willy Tarreau [Thu, 24 Apr 2025 14:31:47 +0000 (16:31 +0200)] 
MINOR: resolvers: add command-line argument -4 to force IPv4-only DNS

In order to ease troubleshooting and testing, the new "-4" command line
argument enforces queries and processing of "A" DNS records only, i.e.
those representing IPv4 addresses. This can be useful when a host lack
end-to-end dual-stack connectivity. This overrides the global
"dns-accept-family" directive and is equivalent to value "ipv4".

3 months agoMEDIUM: resolvers: add global "dns-accept-family" directive
Willy Tarreau [Thu, 24 Apr 2025 14:29:11 +0000 (16:29 +0200)] 
MEDIUM: resolvers: add global "dns-accept-family" directive

By default, DNS resolvers accept both IPv4 and IPv6 addresses. This can be
influenced by the "resolve-prefer" keywords on server lines as well as the
family argument to the "do-resolve" action, but that is only a preference,
which does not block the other family from being used when it's alone. In
some environments where dual-stack is not usable, stumbling on an unreachable
IPv6-only DNS record can cause significant trouble as it will replace a
previous IPv4 one which would possibly have continued to work till next
request. The "dns-accept-family" global option permits to enforce usage of
only one (or both) address families. The argument is a comma-delimited list
of the following words:
  - "ipv4": query and accept IPv4 addresses ("A" records)
  - "ipv6": query and accept IPv6 addresses ("AAAA" records)

When a single family is used, no request will be sent to resolvers for the
other family, and any response for the othe family will be ignored. The
default value is "ipv4,ipv6", which effectively enables both families.

3 months agoBUG/MINOR: master/cli: properly trim the '@@' process name in error messages
Willy Tarreau [Thu, 24 Apr 2025 15:47:23 +0000 (17:47 +0200)] 
BUG/MINOR: master/cli: properly trim the '@@' process name in error messages

When '@@' alone is sent on the master CLI (no trailing LF), we get an
error that displays anything past these two characters in the buffer
since there's no room for a \0. Let's make sure to limit the length of
the process name in this case. No backport is needed since this was added
with 00c967fac4 ("MINOR: master/cli: support bidirectional communications
with workers").

3 months agoCLEANUP: applet: Remove unsued rule pointer in appctx structure
Christopher Faulet [Thu, 24 Apr 2025 14:19:11 +0000 (16:19 +0200)] 
CLEANUP: applet: Remove unsued rule pointer in appctx structure

Thanks to previous commits, the "rule" field in the appctx structure is no
longer used. So we can safely remove it.

3 months agoMINOR: applet: Save the "use-service" rule in the stream to init a service applet
Christopher Faulet [Thu, 24 Apr 2025 14:08:48 +0000 (16:08 +0200)] 
MINOR: applet: Save the "use-service" rule in the stream to init a service applet

When a service is initialized, the "use-service" rule that was executed is
now saved in the stream, using "current_rule" field, instead of saving it
into the applet context. It is safe to do so becaues this field is unused at
this stage. To avoid any issue, it is reset after the service
initialization. Doing so, it is no longer necessary to save it in the applet
context. It was the last usage of the rule pointer in the applet context.

The init functions for TCP and HTTP lua services were updated accordingly.

3 months agoMINOR: hlua: Use the applet name in error messages for lua services
Christopher Faulet [Thu, 24 Apr 2025 13:59:31 +0000 (15:59 +0200)] 
MINOR: hlua: Use the applet name in error messages for lua services

The lua function name was used in error messages of HTTP/TCP lua services
while the applet name can be used. Concretely, this will not change
anything, because when a lua service is regiestered, the lua function name
is used to name the applet. But it is easier, cleaner and more logicial
because it is really the applet name that should be displayed in these error
messages.

3 months agoMINOR: cache: Add a pointer on the cache in the cache applet context
Christopher Faulet [Thu, 24 Apr 2025 13:48:57 +0000 (15:48 +0200)] 
MINOR: cache: Add a pointer on the cache in the cache applet context

Thanks to this change, when a response is delivered from the cache, it is no
longer necessary to get the cache filter configuration from the http
"use-cache" rule saved in the appctx to get the currently used cache. It was
a bit complex to get an info that can be directly and naturally stored in
the cache applet context.

3 months agoMINOR: cli/applet: Move appctx fields only used by the CLI in a private context
Christopher Faulet [Thu, 24 Apr 2025 09:17:07 +0000 (11:17 +0200)] 
MINOR: cli/applet: Move appctx fields only used by the CLI in a private context

There are several fields in the appctx structure only used by the CLI. To
make things cleaner, all these fields are now placed in a dedicated context
inside the appctx structure. The final goal is to move it in the service
context and add an API for cli commands to get a command coontext inside the
cli context.

3 months agoBUG/MINOR: ring: Fix I/O handler of "show event" command to not rely on the SC
Christopher Faulet [Wed, 23 Apr 2025 14:38:25 +0000 (16:38 +0200)] 
BUG/MINOR: ring: Fix I/O handler of "show event" command to not rely on the SC

Thanks to the CLI refactoring ("MAJOR: cli: Refacor parsing and execution of
pipelined commands"), it is possible to fix "show event" I/O handle function
to no longer use the SC.

When the applet API was refactored to no longer manipulate the channels or
the stream-connectors, this part was missed. However, without the patch
above, it could not be fixed. It is now possible so let's do it.

This patch must not be backported becaues it depends on refactoring of the
CLI applet.

3 months agoBUG/MINOR: hlua: Fix I/O handler of lua CLI commands to not rely on the SC
Christopher Faulet [Wed, 23 Apr 2025 14:32:55 +0000 (16:32 +0200)] 
BUG/MINOR: hlua: Fix I/O handler of lua CLI commands to not rely on the SC

Thanks to the CLI refactoring ("MAJOR: cli: Refacor parsing and execution of
pipelined commands"), it is possible to fix the I/O handler function used by
lua CLI commands to no longer use the SC.

When the applet API was refactored to no longer manipulate the channels or
the stream-connectors, this part was missed. However, without the patch
above, it could not be fixed. It is now possible so let's do it.

This patch must not be backported becaues it depends on refactoring of the
CLI applet.

3 months agoCLEANUP: applet: Update st0/st1 comment in appctx structure
Christopher Faulet [Wed, 23 Apr 2025 14:30:50 +0000 (16:30 +0200)] 
CLEANUP: applet: Update st0/st1 comment in appctx structure

Today, these states are used by almost all applets. So update the comments
of these fields.

3 months agoMINOR: cli: Rename some CLI applet states to reflect recent refactoring
Christopher Faulet [Wed, 23 Apr 2025 14:27:45 +0000 (16:27 +0200)] 
MINOR: cli: Rename some CLI applet states to reflect recent refactoring

CLI_ST_GETREQ state was renamed into CLI_ST_PARSE_CMDLINE and CLI_ST_PARSEREQ
into CLI_ST_PROCESS_CMDLINE to reflect the real action performed in these
states.

3 months agoMAJOR: cli: Refacor parsing and execution of pipelined commands
Christopher Faulet [Wed, 23 Apr 2025 13:57:41 +0000 (15:57 +0200)] 
MAJOR: cli: Refacor parsing and execution of pipelined commands

Before this patch, when pipelined commands were received, each command was
parsed and then excuted before moving to the next command. Pending commands
were not copied in the input buffer of the applet. The major issue with this
way to handle commands is the impossibility to consume inputs from commands
with an I/O handler, like "show events" for instance. It was working thanks
to a "bug" if such commands were the last one on the command line. But it
was impossible to use them followed by another command. And this prevents us
to implement any streaming support for CLI commands.

So we decided to refactor the command line parsing to have something similar
to a basic shell. Now an entire line is parsed, including the payload,
before starting commands execution. The command line is copied in a
dedicated buffer. "appctx->chunk" buffer is used for this purpose. It was an
unsed field, so it is safe to use it here. Once the command line copied, the
commands found on this line are executed. Because the applet input buffer
was flushed, any input can be safely consumed by the CLI applet and is
available for the command I/O handler. Thanks to this change, "show event
-w" command can be followed by a command. And in theory, it should be
possible to implement commands supporting input data streaming. For
instance, the Tetris like lua applet can be used on the CLI now.

Note that the payload, if any, is part of the command line and must be fully
received before starting the commands processing. It means there is still
the limitation to a buffer, but not only for the payload but for the whole
command line. The payload is still necessarily at the end of the command
line and is passed as argument to the last command. Internally, the
"appctx->cli_payload" field was introduced to point on the payload in the
command line buffer.

This patch is quite huge but it cannot easily be splitted. It should not
introduced significant changes.

3 months agoMINOR: cli: Use a full prompt command for bidir connections with workers
Christopher Faulet [Thu, 24 Apr 2025 12:54:55 +0000 (14:54 +0200)] 
MINOR: cli: Use a full prompt command for bidir connections with workers

When a bidirection connection with no command is establisehd with a worker
(so "@@<pid>" alone), a "prompt" command is automatically added to display
the worker's prompt and enter in interactive mode in the worker context.
However, till now, an unfinished command line is sent, with a semicolon
instead of a newline at the end. It is not exactly a bug because this
works. But it is not really expected and could be a problem for future
changes.

So now, a full command line is sent: the "prompt" command finished by a
newline character.

3 months agoBUG/MINOR: cli: Issue an error when too many args are passed for a command
Christopher Faulet [Wed, 23 Apr 2025 13:29:00 +0000 (15:29 +0200)] 
BUG/MINOR: cli: Issue an error when too many args are passed for a command

When a command is parsed to split it in an array of arguments, by default,
at most 64 arguments are supported. But no warning was emitted when there
were too many arguments. Instead, the arguments above the limit were
silently ignored. It could be an issue for some commands, like "add server",
because there was no way to know some arguments were ignored.

Now an error is issued when too many arguments are passed and the command is
not executed.

This patch should be backported to all stable versions.

3 months agoBUG/MINOR: mux-quic: do not decode if conn in error
Amaury Denoyelle [Wed, 23 Apr 2025 15:06:22 +0000 (17:06 +0200)] 
BUG/MINOR: mux-quic: do not decode if conn in error

Add an early return to qcc_decode_qcs() if QCC instance is flagged on
error and connection is scheduled for immediate closure.

The main objective is to ensure to not trigger BUG_ON() from
qcc_set_error() : if a stream decoding has set the connection error, do
not try to process decoding on other streams as they may also encounter
an error. Thus, the connection is closed asap with the first encountered
error case.

This should be backported up to 2.6, after a period of observation.

3 months agoBUG/MINOR: mux-quic: fix possible infinite loop during decoding
Amaury Denoyelle [Wed, 23 Apr 2025 15:27:24 +0000 (17:27 +0200)] 
BUG/MINOR: mux-quic: fix possible infinite loop during decoding

With the support of multiple Rx buffers per QCS instance, stream
decoding in qcc_io_recv() has been reworked for the next haproxy
release. An issue appears in a double while loop : a break statement is
used in the inner loop, which is not sufficient as it should instead
exit from the outer one.

Fix this by replacing break with a goto statement.

No need to backport this.

3 months agoMINOR: h3: simplify h3_rcv_buf return path
Amaury Denoyelle [Wed, 23 Apr 2025 14:57:42 +0000 (16:57 +0200)] 
MINOR: h3: simplify h3_rcv_buf return path

Remove return statement in h3_rcv_buf() in case of stream/connection
error. Instead, reuse already existing label err. This simplifies the
code path. It also fixes the missing leave trace for these cases.

3 months agoMINOR: stick-table: use a separate lock label for updates
Willy Tarreau [Thu, 24 Apr 2025 12:01:13 +0000 (14:01 +0200)] 
MINOR: stick-table: use a separate lock label for updates

Too many locks were sharing STK_TABLE_LOCK making it hard to analyze.
Let's split the already heavily used update lock.

3 months agoMEDIUM: acme: rename "account" into "account-key"
William Lallemand [Thu, 24 Apr 2025 09:06:39 +0000 (11:06 +0200)] 
MEDIUM: acme: rename "account" into "account-key"

Rename the "account" option of the acme section into "account-key".

3 months agoMEDIUM: acme: rename "uri" into "directory"
William Lallemand [Thu, 24 Apr 2025 08:51:41 +0000 (10:51 +0200)] 
MEDIUM: acme: rename "uri" into "directory"

Rename the "uri" option of the acme section into "directory".

3 months agoMEDIUM: acme: use a customized proxy
William Lallemand [Wed, 23 Apr 2025 13:37:57 +0000 (15:37 +0200)] 
MEDIUM: acme: use a customized proxy

Use a customized proxy for the ACME client.

The proxy is initialized at the first acme section parsed.

The proxy uses the httpsclient log format as ACME CA use HTTPS.

3 months agoMINOR: httpclient: add an "https" log-format
William Lallemand [Wed, 23 Apr 2025 13:32:46 +0000 (15:32 +0200)] 
MINOR: httpclient: add an "https" log-format

Add an experimental "https" log-format for the httpclient, it is not
used by the httpclient by default, but could be define in a customized
proxy.

The string is basically a httpslog, with some of the fields replaced by
their backend equivalent or - when not available:

"%ci:%cp [%tr] %ft -/- %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r %[bc_err]/%[ssl_bc_err,hex]/-/-/%[ssl_bc_is_resumed] -/-/-"

3 months agoMINOR: acme/cli: add the 'acme renew' command to the help message
William Lallemand [Wed, 23 Apr 2025 11:59:27 +0000 (13:59 +0200)] 
MINOR: acme/cli: add the 'acme renew' command to the help message

Add the 'acme renew' command to the 'help' command of the CLI.

3 months agoMINOR: http-act: Add 'pause' action to temporarily suspend the message analysis
Christopher Faulet [Tue, 22 Apr 2025 14:08:50 +0000 (16:08 +0200)] 
MINOR: http-act: Add 'pause' action to temporarily suspend the message analysis

The 'pause' HTTP action can now be used to suspend for a moment the message
analysis. A timeout, expressed in milliseconds using a time-format
parameter, or an expression can be used. If an expression is used, errors
and invalid values are ignored.

Internally, the action will set the analysis expiration date on the
corresponding channel to the configured value and it will yield while it is
not expired.

The 'pause' action is available for 'http-request' and 'http-response'
rules.

3 months agoBUG/MEDIUM: mux-spop: Respect the negociated max-frame-size value to send frames
Christopher Faulet [Tue, 22 Apr 2025 13:27:12 +0000 (15:27 +0200)] 
BUG/MEDIUM: mux-spop: Respect the negociated max-frame-size value to send frames

When a SPOP connection is opened, the maximum size for frames is negociated.
This negociated size is properly used when a frame is received and if a too
big frame is detected, an error is triggered. However, the same was not
performed on the sending path. No check was performed on frames sent to the
agent. So it was possible to send frames bigger than the maximum size
supported by the the SPOE agent.

Now, the size of NOTIFY and DISCONNECT frames is checked before sending them
to the agent.

Thanks to Miroslav to have reported the issue.

This patch must be backported to 3.1.

3 months agoCLEANUP: h1: Remove now useless h1_parse_cont_len_header() function
Christopher Faulet [Tue, 15 Apr 2025 17:17:21 +0000 (19:17 +0200)] 
CLEANUP: h1: Remove now useless h1_parse_cont_len_header() function

Since the commit "MINOR: hlua/h1: Use http_parse_cont_len_header() to parse
content-length value", this function is no longer used. So it can be safely
removed.

3 months agoMINOR: hlua/h1: Use http_parse_cont_len_header() to parse content-length value
Christopher Faulet [Tue, 15 Apr 2025 17:14:31 +0000 (19:14 +0200)] 
MINOR: hlua/h1: Use http_parse_cont_len_header() to parse content-length value

Till now, h1_parse_cont_len_header() was used during the H1 message parsing and
by the lua HTTP applets to parse the content-length header value. But a more
generic function was added some years ago doing exactly the same operations. So
let's use it instead.

3 months agoMINOR: mux-h1: Keep custom "Content-Length: 0" header in 1xx and 204 messages
Christopher Faulet [Tue, 15 Apr 2025 17:04:42 +0000 (19:04 +0200)] 
MINOR: mux-h1: Keep custom "Content-Length: 0" header in 1xx and 204 messages

Thanks to the commit "MINOR: mux-h1: Don't remove custom "Content-Length: 0"
header in 1xx and 204 messages", we are now sure that 1xx and 204 responses
were sanitized during the parsing. So, if one of these headers are found in
such responses when sent to the client, it means it was added by hand, via a
"set-header" action for instance. In this context, we are able to make an
exception for the "Content-Length: 0" header, and only this one with this
value, to not break leagacy applications.

So now, a user can force the "Content-Length: 0" header to appear in 1xx and
204 responses by adding the right action in hist configuration.
"Transfer-Encoding" headers are still dropped as "Content-Length" headers
with another value than 0. Note, that in practice, only 101 and 204 are
concerned because other 1xx message are not subject to HTTP analysis.

This patch should fix the issue #2888. There is no reason to backport
it. But if we do so, the patch above must be backported too.

3 months agoMINOR: h1-htx: Skip C-L and T-E headers for 1xx and 204 messages during parsing
Christopher Faulet [Tue, 15 Apr 2025 16:56:18 +0000 (18:56 +0200)] 
MINOR: h1-htx: Skip C-L and T-E headers for 1xx and 204 messages during parsing

According to the RFC9110 and RFC9112, a server must not add 'Content-Length'
or 'Transfer-Encoding' headers into 1xx and 204 responses. So till now,
these headers were dropped from the response when it is sent to the client.

However, it seems more logical to remove it during the message parsing. In
addition to sanitize messages as early as possible, this will allow us to
apply some exception in some cases (This will be the subject of another
patch).

In this patch, 'Content-Length' and 'Transfer-Encoding' headers are removed
from 1xx and 204 responses during the parsing but the same is still
performed during the formatting stage.

3 months agoMINOR: proxy: Add options to drop HTTP trailers during message forwarding
Christopher Faulet [Tue, 15 Apr 2025 13:36:19 +0000 (15:36 +0200)] 
MINOR: proxy: Add options to drop HTTP trailers during message forwarding

In RFC9110, it is stated that trailers could be merged with the
headers. While it should be performed with a speicial care, it may be a
problem for some applications. To avoid any trouble with such applications,
two new options were added to drop trailers during the message forwarding.

On the backend, "http-drop-request-trailers" option can be enabled to drop
trailers from the requests before sending them to the server. And on the
frontend, "http-drop-response-trailers" option can be enabled to drop
trailers from the responses before sending them to the client. The options
can be defined in defaults sections and disabled with "no" keyword.

This patch should fix the issue #2930.

3 months agoCLEANUP: Slightly reorder some proxy option flags to free slots
Christopher Faulet [Tue, 15 Apr 2025 06:40:49 +0000 (08:40 +0200)] 
CLEANUP: Slightly reorder some proxy option flags to free slots

PR_O_TCPCHK_SSL and PR_O_CONTSTATS was shifted to free a slot. The idea is
to have 2 contiguous slots to be able to insert two new options.

3 months agoCLEANUP: proxy: detach the name node in proxy_free_common() instead
Willy Tarreau [Sat, 19 Apr 2025 08:21:19 +0000 (10:21 +0200)] 
CLEANUP: proxy: detach the name node in proxy_free_common() instead

This changes commit d2a9149f0 ("BUG/MINOR: proxy: always detach a proxy
from the names tree on free()") to be cleaner. Aurélien spotted that
the free(p->id) was indeed already done in proxy_free_common(), which is
called before we delete the node. That's still a bit ugly and it only
works because ebpt_delete() does not dereference the key during the
operation. Better play safe and delete the entry before freeing it,
that's more future-proof.

3 months agoBUG/MINOR: proxy: always detach a proxy from the names tree on free()
Willy Tarreau [Fri, 18 Apr 2025 21:50:13 +0000 (23:50 +0200)] 
BUG/MINOR: proxy: always detach a proxy from the names tree on free()

Stephen Farrell reported in issue #2942 that recent haproxy versions
crash if there's no resolv.conf. A quick bisect with his reproducer
showed that it started with commit 4194f75 ("MEDIUM: tree-wide: avoid
manually initializing proxies") which reorders the proxies initialization
sequence a bit. The crash shows a corrupted tree, typically indicating a
use-after-free. With the help of ASAN it was possible to find that a
resolver proxy had been destroyed and freed before the name insertion
that causes the crash, very likely caused by the absence of the needed
resolv.conf:

    #0 0x7ffff72a82f7 in free (/usr/local/lib64/libasan.so.5+0x1062f7)
    #1 0x94c1fd in free_proxy src/proxy.c:436
    #2 0x9355d1 in resolvers_destroy src/resolvers.c:2604
    #3 0x93e899 in resolvers_create_default src/resolvers.c:3892
    #4 0xc6ed29 in httpclient_resolve_init src/http_client.c:1170
    #5 0xc6fbcf in httpclient_create_proxy src/http_client.c:1310
    #6 0x4ae9da in ssl_ocsp_update_precheck src/ssl_ocsp.c:1452
    #7 0xa1b03f in step_init_2 src/haproxy.c:2050

But free_proxy() doesn't delete the ebpt_node that carries the name,
which perfectly explains the situation. This patch simply deletes the
name node and Stephen confirmed that it fixed the problem for him as
well. Let's also free it since the key points to p->id which is never
freed either in this function!

No backport is needed since the patch above was first merged into
3.2-dev10.

3 months agoBUG/MINOR: quic: do not crash on CRYPTO ncbuf alloc failure
Amaury Denoyelle [Fri, 18 Apr 2025 16:02:48 +0000 (18:02 +0200)] 
BUG/MINOR: quic: do not crash on CRYPTO ncbuf alloc failure

To handle out-of-order received CRYPTO frames, a ncbuf instance is
allocated. This is done via the helper quic_get_ncbuf().

Buffer allocation was improperly checked. In case b_alloc() fails, it
crashes due to a BUG_ON(). Fix this by removing it. The function now
returns NULL on allocation failure, which is already properly handled in
its caller qc_handle_crypto_frm().

This should fix the last reported crash from github issue #2935.

This must be backported up to 2.6.

3 months ago[RELEASE] Released version 3.2-dev11 v3.2-dev11
Willy Tarreau [Fri, 18 Apr 2025 12:19:47 +0000 (14:19 +0200)] 
[RELEASE] Released version 3.2-dev11

Released version 3.2-dev11 with the following main changes :
    - CI: enable weekly QuicTLS build
    - DOC: management: slightly clarify the prefix role of the '@' command
    - DOC: management: add a paragraph about the limitations of the '@' prefix
    - MINOR: master/cli: support bidirectional communications with workers
    - MEDIUM: ssl/ckch: add filename and linenum argument to crt-store parsing
    - MINOR: acme: add the acme section in the configuration parser
    - MINOR: acme: add configuration for the crt-store
    - MINOR: acme: add private key configuration
    - MINOR: acme/cli: add the 'acme renew' command
    - MINOR: acme: the acme section is experimental
    - MINOR: acme: get the ACME directory
    - MINOR: acme: handle the nonce
    - MINOR: acme: check if the account exist
    - MINOR: acme: generate new account
    - MINOR: acme: newOrder request retrieve authorizations URLs
    - MINOR: acme: allow empty payload in acme_jws_payload()
    - MINOR: acme: get the challenges object from the Auth URL
    - MINOR: acme: send the request for challenge ready
    - MINOR: acme: implement a check on the challenge status
    - MINOR: acme: generate the CSR in a X509_REQ
    - MINOR: acme: finalize by sending the CSR
    - MINOR: acme: verify the order status once finalized
    - MINOR: acme: implement retrieval of the certificate
    - BUG/MINOR: acme: ckch_conf_acme_init() when no filename
    - MINOR: ssl/ckch: handle ckch_conf in ckchs_dup() and ckch_conf_clean()
    - MINOR: acme: copy the original ckch_store
    - MEDIUM: acme: replace the previous ckch instance with new ones
    - MINOR: acme: schedule retries with a timer
    - BUILD: acme: enable the ACME feature when JWS is present
    - BUG/MINOR: cpu-topo: check the correct variable for NULL after malloc()
    - BUG/MINOR: acme: key not restored upon error in acme_res_certificate()
    - BUG/MINOR: thread: protect thread_cpus_enabled_at_boot with USE_THREAD
    - MINOR: acme: default to 2048bits for RSA
    - DOC: acme: explain how to configure and run ACME
    - BUG/MINOR: debug: remove the trailing \n from BUG_ON() statements
    - DOC: config: add the missing "profiling.memory" to the global kw index
    - DOC: config: add the missing "force-cfg-parser-pause" to the global kw index
    - DEBUG: init: report invalid characters in debug description strings
    - DEBUG: rename DEBUG_GLITCHES to DEBUG_COUNTERS and enable it by default
    - DEBUG: counters: make COUNT_IF() only appear at DEBUG_COUNTERS>=1
    - DEBUG: counters: add the ability to enable/disable updating the COUNT_IF counters
    - MINOR: tools: let dump_addr_and_bytes() support dumping before the offset
    - MINOR: debug: in call traces, dump the 8 bytes before the return address, not after
    - MINOR: debug: detect call instructions and show the branch target in backtraces
    - BUG/MINOR: acme: fix possible NULL deref
    - CLEANUP: acme: stored value is overwritten before it can be used
    - BUILD: incompatible pointer type suspected with -DDEBUG_UNIT
    - BUG/MINOR: http-ana: Properly detect client abort when forwarding the response
    - BUG/MEDIUM: http-ana: Report 502 from req analyzer only during rsp forwarding
    - CI: fedora rawhide: enable unit tests
    - DOC: configuration: fix a typo in ACME documentation
    - MEDIUM: sink: add a new dpapi ring buffer
    - Revert "BUG/MINOR: acme: key not restored upon error in acme_res_certificate()"
    - BUG/MINOR: acme: key not restored upon error in acme_res_certificate() V2
    - BUG/MINOR: acme: fix the exponential backoff of retries
    - DOC: configuration: specify limitations of ACME for 3.2
    - MINOR: acme: emit logs instead of ha_notice
    - MINOR: acme: add a success message to the logs
    - BUG/MINOR: acme/cli: fix certificate name in error message
    - MINOR: acme: register the task in the ckch_store
    - MINOR: acme: free acme_ctx once the task is done
    - BUG/MEDIUM: h3: trim whitespaces when parsing headers value
    - BUG/MEDIUM: h3: trim whitespaces in header value prior to QPACK encoding
    - BUG/MINOR: h3: filter upgrade connection header
    - BUG/MINOR: h3: reject invalid :path in request
    - BUG/MINOR: h3: reject request URI with invalid characters
    - MEDIUM: h3: use absolute URI form with :authority
    - BUG/MEDIUM: hlua: fix hlua_applet_{http,tcp}_fct() yield regression (lost data)
    - BUG/MINOR: mux-h2: prevent past scheduling with idle connections
    - BUG/MINOR: rhttp: fix reconnect if timeout connect unset
    - BUG/MINOR: rhttp: ensure GOAWAY can be emitted after reversal
    - BUG/MINOR: mux-h2: do not apply timer on idle backend connection
    - MINOR: mux-h2: refactor idle timeout calculation
    - MINOR: mux-h2: prepare to support PING emission
    - MEDIUM: server/mux-h2: implement idle-ping on backend side
    - MEDIUM: listener/mux-h2: implement idle-ping on frontend side
    - MINOR: mux-h2: do not emit GOAWAY on idle ping expiration
    - MINOR: mux-h2: handle idle-ping on conn reverse
    - BUILD: makefile: enable backtrace by default on musl
    - BUG/MINOR: threads: set threads_idle and threads_harmless even with no threads
    - BUG/MINOR debug: fix !USE_THREAD_DUMP in ha_thread_dump_fill()
    - BUG/MINOR: wdt/debug: avoid signal re-entrance between debugger and watchdog
    - BUG/MINOR: debug: detect and prevent re-entrance in ha_thread_dump_fill()
    - MINOR: debug: do not statify a few debugging functions often used with wdt/dbg
    - MINOR: tools: also protect the library name resolution against concurrent accesses
    - MINOR: tools: protect dladdr() against reentrant calls from the debug handler
    - MINOR: debug: protect ha_dump_backtrace() against risks of re-entrance
    - MINOR: tinfo: keep a copy of the pointer to the thread dump buffer
    - MINOR: debug: always reset the dump pointer when done
    - MINOR: debug: remove unused case of thr!=tid in ha_thread_dump_one()
    - MINOR: pass a valid buffer pointer to ha_thread_dump_one()
    - MEDIUM: wdt: always make the faulty thread report its own warnings
    - MINOR: debug: make ha_stuck_warning() only work for the current thread
    - MINOR: debug: make ha_stuck_warning() print the whole message at once
    - CLEANUP: debug: no longer set nor use TH_FL_DUMPING_OTHERS
    - MINOR: sched: add a new function is_sched_alive() to report scheduler's health
    - MINOR: wdt: use is_sched_alive() instead of keeping a local ctxsw copy
    - MINOR: sample: add 4 new sample fetches for clienthello parsing
    - REGTEST: add new reg-test for the 4 new clienthello fetches
    - MINOR: servers: Move the per-thread server initialization earlier
    - MINOR: proxies: Initialize the per-thread structure earlier.
    - MINOR: servers: Provide a pointer to the server in srv_per_tgroup.
    - MINOR: lb_fwrr: Move the next weight out of fwrr_group.
    - MINOR: proxies: Add a per-thread group lbprm struct.
    - MEDIUM: lb_fwrr: Use one ebtree per thread group.
    - MEDIUM: lb_fwrr: Don't start all thread groups on the same server.
    - MINOR: proxies: Do stage2 initialization for sinks too

3 months agoMINOR: proxies: Do stage2 initialization for sinks too
Olivier Houchard [Thu, 17 Apr 2025 15:16:44 +0000 (17:16 +0200)] 
MINOR: proxies: Do stage2 initialization for sinks too

In check_config_validity(), we initialize the proxy in several stages.
We do so for the sink list for stage1, but not for stage2. It may not be
needed right now, but it may become needed in the future, so do it
anyway.

3 months agoMEDIUM: lb_fwrr: Don't start all thread groups on the same server.
Olivier Houchard [Thu, 17 Apr 2025 14:45:29 +0000 (16:45 +0200)] 
MEDIUM: lb_fwrr: Don't start all thread groups on the same server.

Now that all there is one tree per thread group, all thread groups will
start on the same server. To prevent that, just insert the servers in a
different order for each thread group.

3 months agoMEDIUM: lb_fwrr: Use one ebtree per thread group.
Olivier Houchard [Thu, 17 Apr 2025 14:31:44 +0000 (16:31 +0200)] 
MEDIUM: lb_fwrr: Use one ebtree per thread group.

When using the round-robin load balancer, the major source of contention
is the lbprm lock, that has to be held every time we pick a server.
To mitigate that, make it so there are one tree per thread-group, and
one lock per thread-group. That means we now have a lb_fwrr_per_tgrp
structure that will contain the two lb_fwrr_groups (active and backup) as well
as the lock to protect them in the per-thread lbprm struct, and all
fields in the struct server are now moved to the per-thread structure
too.
Those changes are mostly mechanical, and brings good performances
improvment, on a 64-cores AMD CPU, with 64 servers configured, we could
process about 620000 requests par second, and we now can process around
1400000 requests per second.

3 months agoMINOR: proxies: Add a per-thread group lbprm struct.
Olivier Houchard [Thu, 17 Apr 2025 14:10:48 +0000 (16:10 +0200)] 
MINOR: proxies: Add a per-thread group lbprm struct.

Add a new structure in the per-thread groups proxy structure, that will
contain whatever is per-thread group in lbprm.
It will be accessed as p->per_tgrp[tgid].lbprm.

3 months agoMINOR: lb_fwrr: Move the next weight out of fwrr_group.
Olivier Houchard [Thu, 17 Apr 2025 13:50:33 +0000 (15:50 +0200)] 
MINOR: lb_fwrr: Move the next weight out of fwrr_group.

Move the "next_weight" outside of fwrr_group, and inside struct lb_fwrr
directly, one for the active servers, one for the backup servers.
We will soon have one fwrr_group per thread group, but next_weight will
be global to all of them.

3 months agoMINOR: servers: Provide a pointer to the server in srv_per_tgroup.
Olivier Houchard [Thu, 17 Apr 2025 09:20:24 +0000 (11:20 +0200)] 
MINOR: servers: Provide a pointer to the server in srv_per_tgroup.

Add a pointer to the server into the struct srv_per_tgroup, so that if
we only have access to that srv_per_tgroup, we can come back to the
corresponding server.

3 months agoMINOR: proxies: Initialize the per-thread structure earlier.
Olivier Houchard [Thu, 17 Apr 2025 15:05:07 +0000 (17:05 +0200)] 
MINOR: proxies: Initialize the per-thread structure earlier.

Move the call to initialize the proxy's per-thread structure earlier
than currently done, so that they are usable when we're initializing the
load balancers.

3 months agoMINOR: servers: Move the per-thread server initialization earlier
Olivier Houchard [Thu, 17 Apr 2025 08:42:25 +0000 (10:42 +0200)] 
MINOR: servers: Move the per-thread server initialization earlier

Move the code responsible for calling per-thread server initialization
earlier than it was done, so that per-thread structures are available a
bit later, when we initialize load-balancing.

3 months agoREGTEST: add new reg-test for the 4 new clienthello fetches
Mariam John [Wed, 16 Apr 2025 13:36:08 +0000 (08:36 -0500)] 
REGTEST: add new reg-test for the 4 new clienthello fetches

Add a reg-test which uses the 4 fetches:

- req.ssl_cipherlist
- req.ssl_sigalgs
- req.ssl_keyshare_groups
- req.ssl_supported_groups

3 months agoMINOR: sample: add 4 new sample fetches for clienthello parsing
Mariam John [Wed, 16 Apr 2025 13:36:07 +0000 (08:36 -0500)] 
MINOR: sample: add 4 new sample fetches for clienthello parsing

This patch contains this 4 new fetches and doc changes for the new fetches:

- req.ssl_cipherlist
- req.ssl_sigalgs
- req.ssl_keyshare_groups
- req.ssl_supported_groups

Towards:#2532

3 months agoMINOR: wdt: use is_sched_alive() instead of keeping a local ctxsw copy
Willy Tarreau [Thu, 17 Apr 2025 13:26:30 +0000 (15:26 +0200)] 
MINOR: wdt: use is_sched_alive() instead of keeping a local ctxsw copy

Now we can simply call is_sched_alive() on the local thread to verify
that the scheduler is still ticking instead of having to keep a copy of
the ctxsw and comparing it. It's cleaner, doesn't require to maintain
a local copy, doesn't rely on activity[] (whose purpose is mainly for
observation and debugging), and shows how this could be extended later
to cover other use cases. Practically speaking this doesn't change
anything however, the algorithm is still the same.

3 months agoMINOR: sched: add a new function is_sched_alive() to report scheduler's health
Willy Tarreau [Thu, 17 Apr 2025 13:24:08 +0000 (15:24 +0200)] 
MINOR: sched: add a new function is_sched_alive() to report scheduler's health

This verifies that the scheduler is still ticking without having to
access the activity[] array nor keeping local copies of the ctxsw
counter. It just tests and sets a flag that is reset after each
return from a ->process() function.

3 months agoCLEANUP: debug: no longer set nor use TH_FL_DUMPING_OTHERS
Willy Tarreau [Thu, 17 Apr 2025 13:35:50 +0000 (15:35 +0200)] 
CLEANUP: debug: no longer set nor use TH_FL_DUMPING_OTHERS

TH_FL_DUMPING_OTHERS was being used to try to perform exclusion between
threads running "show threads" and those producing warnings. Now that it
is much more cleanly handled, we don't need that type of protection
anymore, which was adding to the complexity of the solution. Let's just
get rid of it.

3 months agoMINOR: debug: make ha_stuck_warning() print the whole message at once
Willy Tarreau [Thu, 17 Apr 2025 06:59:45 +0000 (08:59 +0200)] 
MINOR: debug: make ha_stuck_warning() print the whole message at once

It has been noticed quite a few times during troubleshooting and even
testing that warnings can happen in avalanches from multiple threads
at the same time, and that their reporting it interleaved bacause the
output is produced in small chunks. Originally, this code inspired by
the panic code aimed at making sure to log whatever could be emitted
in case it would crash later. But this approach was wrong since writes
are atomic, and performing 5 writes in sequence in each dumping thread
also means that the outputs can be mixed up at 5 different locations
between multiple threads. The output of warnings is never very long,
and the stack-based buffer is 4kB so let's just concatenate everything
in the buffer and emit it at once using a single write(). Now there's
no longer this confusion on the output.

3 months agoMINOR: debug: make ha_stuck_warning() only work for the current thread
Willy Tarreau [Thu, 17 Apr 2025 06:54:43 +0000 (08:54 +0200)] 
MINOR: debug: make ha_stuck_warning() only work for the current thread

Since we no longer call it with a foreign thread, let's simplify its code
and get rid of the special cases that were relying on ha_thread_dump_fill()
and synchronization with a remote thread. We're not only dumping the
current thread so ha_thread_dump_one() is sufficient.

3 months agoMEDIUM: wdt: always make the faulty thread report its own warnings
Willy Tarreau [Thu, 17 Apr 2025 06:42:36 +0000 (08:42 +0200)] 
MEDIUM: wdt: always make the faulty thread report its own warnings

Warnings remain tricky to deal with, especially for other threads as
they require some inter-thread synchronization that doesn't cope very
well with other parallel activities such as "show threads" for example.

However there is nothing that forces us to handle them this way. The
panic for example is already handled by bouncing the WDT signal to the
faulty thread.

This commit rearranges the WDT handler to make a better used of this
existing signal bouncing feature of the WDT handler so that it's no
longer limited to panics but can also deal with warnings. In order not
to bounce on all wakeups, we only bounce when there is a suspicion,
that is, when the warning timer has been crossed. We'll let the target
thread verify the stuck flag and context switch count by itself to
decide whether or not to panic, warn, or just do nothing and update
the counters.

As a bonus, now all warning traces look the same regardless of the
reporting thread:

   call trace(16):
   |       0x6bc733 <01 00 00 e8 6d e6 de ff]: ha_dump_backtrace+0x73/0x309 > main-0x2570
   |       0x6bd37a <00 00 00 e8 d6 fb ff ff]: ha_thread_dump_fill+0xda/0x104 > ha_thread_dump_one
   |       0x6bd625 <00 00 00 e8 7b fc ff ff]: ha_stuck_warning+0xc5/0x19e > ha_thread_dump_fill
   |       0x7b2b60 <64 8b 3b e8 00 aa f0 ff]: wdt_handler+0x1f0/0x212 > ha_stuck_warning
   | 0x7fd7e2cef3a0 <00 00 00 00 0f 1f 40 00]: libpthread:+0x123a0
   | 0x7ffc6af9e634 <85 a6 00 00 00 0f 01 f9]: linux-vdso:__vdso_gettimeofday+0x34/0x2b0
   |       0x6bad74 <7c 24 10 e8 9c 01 df ff]: sc_conn_io_cb+0x9fa4 > main-0x2400
   |       0x67c457 <89 f2 4c 89 e6 41 ff d0]: main+0x1cf147
   |       0x67d401 <48 89 df e8 8f ed ff ff]: cli_io_handler+0x191/0xb38 > main+0x1cee80
   |       0x6dd605 <40 48 8b 45 60 ff 50 18]: task_process_applet+0x275/0xce9

3 months agoMINOR: pass a valid buffer pointer to ha_thread_dump_one()
Willy Tarreau [Wed, 16 Apr 2025 14:48:13 +0000 (16:48 +0200)] 
MINOR: pass a valid buffer pointer to ha_thread_dump_one()

The goal is to let the caller deal with the pointer so that the function
only has to fill that buffer without worrying about locking. This way,
synchronous dumps from "show threads" are produced and emitted directly
without causing undesired locking of the buffer nor risking causing
confusion about thread_dump_buffer containing bits from an interrupted
dump in progress.

It's only the caller that's responsible for notifying the requester of
the end of the dump by setting bit 0 of the pointer if needed (i.e. it's
only done in the debug handler).

3 months agoMINOR: debug: remove unused case of thr!=tid in ha_thread_dump_one()
Willy Tarreau [Thu, 10 Apr 2025 07:03:05 +0000 (09:03 +0200)] 
MINOR: debug: remove unused case of thr!=tid in ha_thread_dump_one()

This function was initially designed to dump any threadd into the presented
buffer, but the way it currently works is that it's always called for the
current thread, and uses the distinction between coming from a sighandler
or being called directly to detect which thread is the caller.

Let's simplify all this by replacing thr with tid everywhere, and using
the thread-local pointers where it makes sense (e.g. th_ctx, th_ctx etc).
The confusing "from_signal" argument is now replaced with "is_caller"
which clearly states whether or not the caller declares being the one
asking for the dump (the logic is inverted, but there are only two call
places with a constant).

3 months agoMINOR: debug: always reset the dump pointer when done
Willy Tarreau [Thu, 10 Apr 2025 11:55:52 +0000 (13:55 +0200)] 
MINOR: debug: always reset the dump pointer when done

We don't need to copy the old dump pointer to the thread_dump_pointer
area anymore to indicate a dump is collected. It used to be done as an
artificial way to keep the pointer for the post-mortem analysis but
since we now have this pointer stored separately, that's no longer
needed and it simplifies the mechanim to reset it.

3 months agoMINOR: tinfo: keep a copy of the pointer to the thread dump buffer
Willy Tarreau [Thu, 10 Apr 2025 06:29:39 +0000 (08:29 +0200)] 
MINOR: tinfo: keep a copy of the pointer to the thread dump buffer

Instead of using the thread dump buffer for post-mortem analysis, we'll
keep a copy of the assigned pointer whenever it's used, even for warnings
or "show threads". This will offer more opportunities to figure from a
core what happened, and will give us more freedom regarding the value of
the thread_dump_buffer itself. For example, even at the end of the dump
when the pointer is reset, the last used buffer is now preserved.

3 months agoMINOR: debug: protect ha_dump_backtrace() against risks of re-entrance
Willy Tarreau [Fri, 4 Apr 2025 16:11:23 +0000 (18:11 +0200)] 
MINOR: debug: protect ha_dump_backtrace() against risks of re-entrance

If a thread is dumping itself (warning, show thread etc) and another one
wants to dump the state of all threads (e.g. panic), it may interrupt the
first one during backtrace() and re-enter it from the signal handler,
possibly triggering a deadlock in the underlying libc. Let's postpone
the debug signal delivery at this point until the call ends in order to
avoid this.

3 months agoMINOR: tools: protect dladdr() against reentrant calls from the debug handler
Willy Tarreau [Fri, 4 Apr 2025 16:08:45 +0000 (18:08 +0200)] 
MINOR: tools: protect dladdr() against reentrant calls from the debug handler

If a thread is currently resolving a symbol while another thread triggers
a thread dump, the current thread may enter the debug handler and call
resolve_sym_addr() again, possibly deadlocking if the underlying libc
uses locking. Let's postpone the debug signal delivery in this area
during the call. This will slow the resolution a little bit but we don't
care, it's not supposed to happen often and it must remain rock-solid.

3 months agoMINOR: tools: also protect the library name resolution against concurrent accesses
Willy Tarreau [Fri, 4 Apr 2025 14:56:44 +0000 (16:56 +0200)] 
MINOR: tools: also protect the library name resolution against concurrent accesses

This is an extension of eb41d768f ("MINOR: tools: use only opportunistic
symbols resolution"). It also makes sure we're not calling dladddr() in
parallel to dladdr_and_size(), as a preventive measure against some
potential deadlocks in the inner layers of the libc.

3 months agoMINOR: debug: do not statify a few debugging functions often used with wdt/dbg
Willy Tarreau [Tue, 15 Apr 2025 07:25:27 +0000 (09:25 +0200)] 
MINOR: debug: do not statify a few debugging functions often used with wdt/dbg

A few functions are used when debugging debug signals and watchdog, but
being static, they're not resolved and are hard to spot in dumps, and
they appear as any random other function plus an offset. Let's just not
mark them static anymore, it only hurts:
  - cli_io_handler_show_threads()
  - debug_run_cli_deadlock()
  - debug_parse_cli_loop()
  - debug_parse_cli_panic()

3 months agoBUG/MINOR: debug: detect and prevent re-entrance in ha_thread_dump_fill()
Willy Tarreau [Fri, 4 Apr 2025 16:27:42 +0000 (18:27 +0200)] 
BUG/MINOR: debug: detect and prevent re-entrance in ha_thread_dump_fill()

In the following trace trying to abuse the watchdog from the CLI's
"debug dev loop" command running in parallel to "show threads" loops,
it's clear that some re-entrance may happen in ha_thread_dump_fill().

A first minimal fix consists in using a test-and-set on the flag
indicating that the function is currently dumping threads, so that
the one from the signal just returns. However the caller should be
made more reliable to serialize all of this, that's for future
work.

Here's an example capture of 7 threads stuck waiting for each other:
  (gdb) bt
  #0  0x00007fe78d78e147 in sched_yield () from /lib64/libc.so.6
  #1  0x0000000000674a05 in ha_thread_relax () at src/thread.c:356
  #2  0x00000000005ba4f5 in ha_thread_dump_fill (thr=2, buf=0x7ffdd8e08ab0) at src/debug.c:402
  #3  ha_thread_dump_fill (buf=0x7ffdd8e08ab0, thr=<optimized out>) at src/debug.c:384
  #4  0x00000000005baac4 in ha_stuck_warning (thr=thr@entry=2) at src/debug.c:840
  #5  0x00000000006a360d in wdt_handler (sig=<optimized out>, si=<optimized out>, arg=<optimized out>) at src/wdt.c:156
  #6  <signal handler called>
  #7  0x00007fe78d78e147 in sched_yield () from /lib64/libc.so.6
  #8  0x0000000000674a05 in ha_thread_relax () at src/thread.c:356
  #9  0x00000000005ba4c2 in ha_thread_dump_fill (thr=2, buf=0x7fe78f2d6420) at src/debug.c:426
  #10 ha_thread_dump_fill (buf=0x7fe78f2d6420, thr=2) at src/debug.c:384
  #11 0x00000000005ba7c6 in cli_io_handler_show_threads (appctx=0x2a89ab0) at src/debug.c:548
  #12 0x000000000057ea43 in cli_io_handler (appctx=0x2a89ab0) at src/cli.c:1176
  #13 0x00000000005d7885 in task_process_applet (t=0x2a82730, context=0x2a89ab0, state=<optimized out>) at src/applet.c:920
  #14 0x0000000000659002 in run_tasks_from_lists (budgets=budgets@entry=0x7ffdd8e0a5c0) at src/task.c:644
  #15 0x0000000000659bd7 in process_runnable_tasks () at src/task.c:886
  #16 0x00000000005cdcc9 in run_poll_loop () at src/haproxy.c:2858
  #17 0x00000000005ce457 in run_thread_poll_loop (data=<optimized out>) at src/haproxy.c:3075
  #18 0x0000000000430628 in main (argc=<optimized out>, argv=<optimized out>) at src/haproxy.c:3665

3 months agoBUG/MINOR: wdt/debug: avoid signal re-entrance between debugger and watchdog
Willy Tarreau [Fri, 4 Apr 2025 15:20:25 +0000 (17:20 +0200)] 
BUG/MINOR: wdt/debug: avoid signal re-entrance between debugger and watchdog

As seen in issue #2860, there are some situations where a watchdog could
trigger during the debug signal handler, and where similarly the debug
signal handler may trigger during the wdt handler. This is really bad
because it could trigger some deadlocks inside inner libc code such as
dladdr() or backtrace() since the code will not protect against re-
entrance but only against concurrent accesses.

A first attempt was made using ha_sigmask() but that's not always very
convenient because the second handler is called immediately after
unblocking the signal and before returning, leaving signal cascades in
backtrace. Instead, let's mark which signals to block at registration
time. Here we're blocking wdt/dbg for both signals, and optionally
SIGRTMAX if DEBUG_DEV is used as that one may also be used in this case.

This should be backported at least to 3.1.

3 months agoBUG/MINOR debug: fix !USE_THREAD_DUMP in ha_thread_dump_fill()
Willy Tarreau [Thu, 17 Apr 2025 08:28:37 +0000 (10:28 +0200)] 
BUG/MINOR debug: fix !USE_THREAD_DUMP in ha_thread_dump_fill()

The function must make sure to return NULL for foreign threads and
the local buffer for the current thread in this case, otherwise panics
(and sometimes even warnings) will segfault when USE_THREAD_DUMP is
disabled. Let's slightly re-arrange the function to reduce the #if/else
since we have to specifically handle the case of !USE_THREAD_DUMP anyway.

This needs to be backported wherever b8adef065d ("MEDIUM: debug: on
panic, make the target thread automatically allocate its buf") was
backported (at least 2.8).

3 months agoBUG/MINOR: threads: set threads_idle and threads_harmless even with no threads
Willy Tarreau [Tue, 15 Apr 2025 07:03:35 +0000 (09:03 +0200)] 
BUG/MINOR: threads: set threads_idle and threads_harmless even with no threads

Some signal handlers rely on these to decide about the level of detail to
provide in dumps, so let's properly fill the info about entering/leaving
idle. Note that for consistency with other tests we're using bitops with
t->ltid_bit, while we could simply assign 0/1 to the fields. But it makes
the code more readable and the whole difference is only 88 bytes on a 3MB
executable.

This bug is not important, and while older versions are likely affected
as well, it's not worth taking the risk to backport this in case it would
wake up an obscure bug.

3 months agoBUILD: makefile: enable backtrace by default on musl
Willy Tarreau [Thu, 17 Apr 2025 14:11:14 +0000 (16:11 +0200)] 
BUILD: makefile: enable backtrace by default on musl

The reason musl builds was not producing exploitable backtraces was
that the toolchain used appears to automatically omit the frame pointer
at -O2 but leaves it at -O0. This patch just makes sure to always append
-fno-omit-frame-pointer to the BACKTRACE cflags and enables the option
with musl where it now works. This will allow us to finally get
exploitable traces from docker images where core dumps are not always
available.

3 months agoMINOR: mux-h2: handle idle-ping on conn reverse
Amaury Denoyelle [Tue, 8 Apr 2025 09:52:41 +0000 (11:52 +0200)] 
MINOR: mux-h2: handle idle-ping on conn reverse

This commit extends MUX H2 connection reversal step to properly take
into account the new idle-ping feature. It first ensures that h2c task
is properly instantiated/freed depending now on both timers and
idle-ping configuration. Also, h2c_update_timeout() is now called
instead of manually requeuing the task, which ensures the proper timer
value is selected depending on the new connection side.

3 months agoMINOR: mux-h2: do not emit GOAWAY on idle ping expiration
Amaury Denoyelle [Thu, 17 Apr 2025 09:14:10 +0000 (11:14 +0200)] 
MINOR: mux-h2: do not emit GOAWAY on idle ping expiration

If idle-ping is activated and h2c task is expired due to missing PING
ACK, consider that the peer is away and the connection can be closed
immediately. GOAWAY emission is thus skipped.

A new test is necessary in h2c_update_timeout() when PING ACK is
currently expected, but the next timer expiration selected is not
idle-ping. This may happen if http-keep-alive/http-request timers are
selected first. In this case, H2_CF_IDL_PING_SENT flag is resetted. This
is necessary to not prevent GOAWAY emission on expiration.