From 6fa63d98527fc2c9f4637c5b82c138a4725d80a9 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Mon, 27 Nov 2017 18:41:32 +0100 Subject: [PATCH] MINOR: early data: Don't rely on CO_FL_EARLY_DATA to wake up streams. Instead of looking for CO_FL_EARLY_DATA to know if we have to try to wake up a stream, because it is waiting for a SSL handshake, instead add a new conn_stream flag, CS_FL_WAIT_FOR_HS. This way we don't have to rely on CO_FL_EARLY_DATA, and we will only wake streams that are actually waiting. --- include/types/connection.h | 1 + src/mux_h2.c | 24 ++++++++++++++++++------ src/ssl_sock.c | 5 ++++- src/stream_interface.c | 4 +++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/types/connection.h b/include/types/connection.h index 4bcac6079..cea61f559 100644 --- a/include/types/connection.h +++ b/include/types/connection.h @@ -70,6 +70,7 @@ enum { CS_FL_ERROR = 0x00000100, /* a fatal error was reported */ CS_FL_RCV_MORE = 0x00000200, /* more bytes to receive but not enough room */ CS_FL_EOS = 0x00001000, /* End of stream */ + CS_FL_WAIT_FOR_HS = 0x00010000, /* This stream is waiting for handhskae */ }; /* cs_shutr() modes */ diff --git a/src/mux_h2.c b/src/mux_h2.c index 7bb51ea41..6c63b8612 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -59,6 +59,7 @@ static struct pool_head *pool_head_h2s; /* other flags */ #define H2_CF_GOAWAY_SENT 0x00000100 // a GOAWAY frame was successfully sent #define H2_CF_GOAWAY_FAILED 0x00000200 // a GOAWAY frame failed to be sent +#define H2_CF_WAIT_FOR_HS 0x00000400 // We did check that at least a stream was waiting for handshake /* H2 connection state, in h2c->st0 */ @@ -2275,14 +2276,25 @@ static int h2_wake(struct connection *conn) } /* - * If we received early data, try to wake any stream, just in case - * at least one of them was waiting for the handshake + * If we received early data, and the handshake is done, wake + * any stream that was waiting for it. */ - if ((conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_EARLY_DATA | CO_FL_HANDSHAKE)) == - CO_FL_EARLY_DATA) { - h2_wake_some_streams(h2c, 0, 0); - conn->flags &= ~CO_FL_EARLY_DATA; + if (!(h2c->flags & H2_CF_WAIT_FOR_HS) && + (conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_HANDSHAKE | CO_FL_EARLY_DATA)) == CO_FL_EARLY_DATA) { + struct eb32_node *node; + struct h2s *h2s; + + h2c->flags |= H2_CF_WAIT_FOR_HS; + node = eb32_lookup_ge(&h2c->streams_by_id, 1); + + while (node) { + h2s = container_of(node, struct h2s, by_id); + if (h2s->cs->flags & CS_FL_WAIT_FOR_HS) + h2s->cs->data_cb->wake(h2s->cs); + node = eb32_next(node); + } } + if (conn->flags & CO_FL_ERROR || conn_xprt_read0_pending(conn) || h2c->st0 == H2_CS_ERROR2 || h2c->flags & H2_CF_GOAWAY_FAILED || (eb_is_empty(&h2c->streams_by_id) && h2c->last_sid >= 0 && diff --git a/src/ssl_sock.c b/src/ssl_sock.c index c2fa45f52..76f842528 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -8711,11 +8711,14 @@ enum act_return ssl_action_wait_for_hs(struct act_rule *rule, struct proxy *px, struct session *sess, struct stream *s, int flags) { struct connection *conn; + struct conn_stream *cs; conn = objt_conn(sess->origin); + cs = objt_cs(s->si[0].end); - if (conn) { + if (conn && cs) { if (conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_SSL_WAIT_HS)) { + cs->flags |= CS_FL_WAIT_FOR_HS; s->req.flags |= CF_READ_NULL; return ACT_RET_YIELD; } diff --git a/src/stream_interface.c b/src/stream_interface.c index 9f61a7510..a78694f78 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -584,7 +584,9 @@ static int si_cs_wake_cb(struct conn_stream *cs) * in the event there's an analyser waiting for the end of * the handshake. */ - if ((conn->flags & (CO_FL_EARLY_DATA | CO_FL_EARLY_SSL_HS)) == CO_FL_EARLY_DATA) { + if (!(conn->flags & (CO_FL_HANDSHAKE | CO_FL_EARLY_SSL_HS)) && + (cs->flags & CS_FL_WAIT_FOR_HS)) { + cs->flags &= ~CS_FL_WAIT_FOR_HS; task_wakeup(si_task(si), TASK_WOKEN_MSG); }