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.

(cherry picked from commit eb3f26d5a023431d28107d29a60f0e923dcfc85e)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 8c5ac22886b7786234c13c4701c8b0f5503ae43f)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit e537945e72d08425ba42860b356621704d0a77e3)
[cf: Applied on stream_interface.c. The stream-connector is replaced by the
     stream-interface but no other change]
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 7225a7e5b3b6f81424b3953c14b7185fde7310bb)
Signed-off-by: Willy Tarreau <w@1wt.eu>
1 file changed