BUG/MEDIUM: conn-stream: Don't reset CS flags on close
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 10 Nov 2021 14:12:47 +0000 (15:12 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 23 Nov 2021 15:34:07 +0000 (16:34 +0100)
commitab3c07542851fbb21d50f52f881de23cc4dab40a
treef77273de63551e8ffeef210b96b7c9daebe50361
parent9a3d885a9229aa4fde298ac9385854817fc5bbfb
BUG/MEDIUM: conn-stream: Don't reset CS flags on close

cs_close() and cs_drain_and_close() are called to close a conn-stream.
cs_shutr() and cs_shutw() are called with the appropriate modes. But the
conn-stream is not released at this stage. However the flags are
reset. Thus, after a cs_close(), we loose shutdown flags. If cs_close() is
performed several times, it is a problem. And indeed, it is possible. On one
hand, the stream-interface may close the conn-stream. On the other end, the
stream always closes it when it is released.

It is a problem for the H1 multiplexer. Because the conn-stream flags are
reset, the shutr and shutw are performed twice. For a delayed shutdown, the
dirty mode is used instead of the normal one because the last call to
h1_shutw() overwrite H1C flags set by the first call. This leads to dirty
shutdowns while normal ones are required. At the end, it is possible to
truncate the messages.

This bug was revealed by the commit a85c522d4 ("BUG/MINOR: mux-h1: Save
shutdown mode if the shutdown is delayed").

This patch is related to the issue #1450. It must be backported as far as
2.0.

(cherry picked from commit f14d750bf7ef6ce95fcf0de14a423c456ebf82c5)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 68a5fa373ead9552c470e14615001653f94dc7ee)
[cf: cs_drain_and_close does not exist on the 2.3]]
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
include/haproxy/connection.h