BUG/MINOR: h2/rhttp: fix HTTP2 conn counters on reverse
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 16 Dec 2024 10:00:23 +0000 (11:00 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 6 Jan 2025 10:28:18 +0000 (11:28 +0100)
commitaedc04be5a1fbf72392e68037c4e23b9aa034dc0
tree7cddc9ae59561a767aa3a2bf56e219bccd8164c9
parent1ad30d66fe199474721cda710199df3a310d929d
BUG/MINOR: h2/rhttp: fix HTTP2 conn counters on reverse

Dedicated HTTP/2 stats proxy counters are available for current and
total number of HTTP/2 connection on both frontend and backend sides.
Both counters are simply incremented into h2_init().

This causes issues when using reverse HTTP. First, increment is not
performed on the expected side, as it is triggered before
h2_conn_reverse() which switches a connection from frontend to backend
or vice versa. For example on active revers side, h2_total_connections
is incremented on the backend only even after connection is reversed and
attached to a listener for the remainder of its lifetime.

h2_open_connections suffers from a similar but arguably worst behavior
as it is also decremented. If increment and decrement operations are not
performed on the same proxy side, which happens for every connection
which has been successfully reversed, it causes an invalid counter
value, possibly with an integer overflow.

To fix this, delay increment operations on reverse HTTP from h2_init()
to h2_conn_reverse(). Both counters are updated only after reverse has
completed, thus using the expected frontend or backend side.

To prevent overflow on h2_open_connections, ensure h2_release()
decrement is not performed if a connection is freed before achieving its
reversal, as in this case it would not have been accounted by H2
counters.

This should be backported up to 2.9.

This should fix github issue #2821.

(cherry picked from commit 8633446337cd322f010ce7b3ca9c257d1ce7848c)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/mux_h2.c