BUG/MEDIUM: stconn: Schedule a shutw on shutr if data must be sent first
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 8 Feb 2023 15:18:48 +0000 (16:18 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 8 Feb 2023 15:35:54 +0000 (16:35 +0100)
commiteb3f26d5a023431d28107d29a60f0e923dcfc85e
treeb75eda667f72ac632df5e7e8e55f36613625153f
parent86207e782cea35c4f85657855ed47ab3295e2695
BUG/MEDIUM: stconn: Schedule a shutw on shutr if data must be sent first

The commit 7f59d68fe ("BUG/MEDIIM: stconn: Flush output data before
forwarding close to write side") introduced a regression. When the read side
is closed, the close is not forwarded to the write side if there are some
pending outgoind data. The idea is to foward data first and the close the
write side. However, when fast-forwarding is enabled and last data block is
received with the read0, the close is never forwarded.

We cannot revert the commit above because it really fix an issue. However,
we can schedule the shutdown for write by setting CF_SHUTW_NOW flag on the
write side. Indeed, it is the purpose of this flag.

To not replicate ugly and hardly maintainable code block at different places
in stconn.c, an helper function is used. Thus, sc_cond_forward_shutw() must
be called to know if the close can be fowarded or not. It returns 1 if it is
possible. In this case, the caller is responsible to forward the close to
the write side. Otherwise, if the close cannot be forwarded, 0 is
returned. It happens when it should not be performed at all. Or when it
should only be delayed, waiting for the input channel to be flushed. In this
last case, the CF_SHUTW_NOW flag is set in the output channel.

This patch should fix the issue #2033. It must be backported with the commit
above, thus at least as far as 2.2.
src/stconn.c