From 58e3208714d8a1ee2fc186f99f9086f682e29447 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 7 Nov 2017 14:41:09 +0100 Subject: [PATCH] BUG/MINOR: h2: correctly check for H2_SF_ES_SENT before closing In h2_shutw() we must not send another empty frame (nor RST) after one has been sent, as the stream is already in HLOC/CLOSED state. --- src/mux_h2.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/mux_h2.c b/src/mux_h2.c index fad28b695e..70dd8ef94c 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -2249,8 +2249,16 @@ static void h2_shutw(struct conn_stream *cs, enum cs_shw_mode mode) return; if (h2s->flags & H2_SF_HEADERS_SENT) { - if (h2_send_empty_data_es(h2s) <= 0) + /* we can cleanly close using an empty data frame only after headers */ + + if (!(h2s->flags & (H2_SF_ES_SENT|H2_SF_RST_SENT)) && + h2_send_empty_data_es(h2s) <= 0) return; + + if (h2s->st == H2_SS_HREM) + h2s->st = H2_SS_CLOSED; + else + h2s->st = H2_SS_HLOC; } else { /* let's signal a wish to close the connection if no headers * were seen as this usually means it's a tcp-request rule which @@ -2260,18 +2268,15 @@ static void h2_shutw(struct conn_stream *cs, enum cs_shw_mode mode) h2c_send_goaway_error(h2s->h2c, h2s) <= 0) return; - if (h2c_send_rst_stream(h2s->h2c, h2s) <= 0) + if (!(h2s->flags & H2_SF_RST_SENT) && + h2c_send_rst_stream(h2s->h2c, h2s) <= 0) return; + + h2s->st = H2_SS_CLOSED; } if (h2s->h2c->mbuf->o && !(cs->conn->flags & CO_FL_XPRT_WR_ENA)) conn_xprt_want_send(cs->conn); - - if (h2s->st == H2_SS_OPEN && !(h2s->flags & H2_SF_RST_SENT)) - h2s->st = H2_SS_HLOC; - else - h2s->st = H2_SS_CLOSED; - } /* Decode the payload of a HEADERS frame and produce the equivalent HTTP/1 -- 2.47.3