]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: h2: stop relying on H2_SS_IDLE / H2_SS_CLOSED
authorWilly Tarreau <w@1wt.eu>
Fri, 5 Oct 2018 08:16:37 +0000 (10:16 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 12 Oct 2018 14:58:01 +0000 (16:58 +0200)
At a few places we check these states to detect if a stream has valid
data/errcode or is one of the two dummy streams (idle or closed). It
will become problematic for outgoing streams as it will not be possible
to report errors for example since the stream will switch from IDLE
state only after sending a HEADERS frame.

There is a safer solution consisting in checking the stream ID, which
may only be zero in the dummy streams. This patch changes the test to
only rely on the stream ID.

src/mux_h2.c

index fee3d536dff0619c9ca1fffe17203ba259f82cce..82542885366610b56a7fae42fa8429045a2313c3 100644 (file)
@@ -537,7 +537,7 @@ static inline __maybe_unused void h2c_error(struct h2c *h2c, enum h2_err err)
 /* marks an error on the stream */
 static inline __maybe_unused void h2s_error(struct h2s *h2s, enum h2_err err)
 {
-       if (h2s->st > H2_SS_IDLE && h2s->st < H2_SS_ERROR) {
+       if (h2s->id && h2s->st < H2_SS_ERROR) {
                h2s->errcode = err;
                h2s->st = H2_SS_ERROR;
                if (h2s->cs)
@@ -1027,8 +1027,7 @@ static int h2c_send_rst_stream(struct h2c *h2c, struct h2s *h2s)
        memcpy(str, "\x00\x00\x04\x03\x00", 5);
 
        write_n32(str + 5, h2c->dsi);
-       write_n32(str + 9, (h2s->st > H2_SS_IDLE && h2s->st < H2_SS_CLOSED) ?
-                 h2s->errcode : H2_ERR_STREAM_CLOSED);
+       write_n32(str + 9, h2s->id ? h2s->errcode : H2_ERR_STREAM_CLOSED);
        ret = b_istput(res, ist2(str, 13));
 
        if (unlikely(ret <= 0)) {
@@ -1044,7 +1043,7 @@ static int h2c_send_rst_stream(struct h2c *h2c, struct h2s *h2s)
        }
 
  ignore:
-       if (h2s->st > H2_SS_IDLE && h2s->st < H2_SS_CLOSED) {
+       if (h2s->id) {
                h2s->flags |= H2_SF_RST_SENT;
                h2s_close(h2s);
        }