MINOR: mux-h2: perform a full cycle shutdown+drain on close
authorWilly Tarreau <w@1wt.eu>
Thu, 21 Oct 2021 20:24:31 +0000 (22:24 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 23 Nov 2021 15:34:07 +0000 (16:34 +0100)
commitd5b903fa408cbdba147d9b17f64df775e0d4e0ab
treef6027b82f98ff87b9b34a74b89975462324e30c9
parent569769fca32d46fed13ae65319300282f50dc10f
MINOR: mux-h2: perform a full cycle shutdown+drain on close

While in H1 we can usually close quickly, in H2 a client might be sending
window updates or anything while we're sending a GOAWAY and the pending
data in the socket buffers at the moment the close() is performed on the
socket results in the output data being lost and an RST being emitted.

One example where this happens easily is with h2spec, which randomly
reports connection resets when waiting for a GOAWAY while haproxy sends
it, as seen in issue #1422. With h2spec it's not window updates that are
causing this but the fact that h2spec has to upload the payload that
comes with invalid frames to accommodate various implementations, and
does that in two different segments. When haproxy aborts on the invalid
frame header, the payload was not yet received and causes an RST to
be sent.

Here we're dealing with this two ways:
  - we perform a shutdown(WR) on the connection to forcefully push pending
    data on a front connection after the xprt is shut and closed ;
  - we drain pending data
  - then we close

This totally solves the issue with h2spec, and the extra cost is very
low, especially if we consider that H2 connections are not set up and
torn down often. This issue was never observed with regular clients,
most likely because this pattern does not happen in regular traffic.

After more testing it could make sense to backport this, at least to
avoid reporting errors on h2spec tests.

(cherry picked from commit 0b222476062d76a1660892a81e9a97962dce1582)
[cf: depends on "MINOR: connection: add a new CO_FL_WANT_DRAIN flag to force
     drain on close". This patch is in fact a bug fix, related to the issue
     #1297.]
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit daa0e5f7d152619962a81983d2e7391246a6e7b4)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/mux_h2.c