From 51ad2f2d9e18c816625afd0de7c13e8de2e9b328 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Mon, 4 May 2020 08:26:48 +0100 Subject: [PATCH] h2: client sid: must be allocated at header send There is no way to allocate a client wsi mux sid before the headers are send, because we don't know the order in which new wsi headers will be sent and so seen by the peer. The peer inisists that sid indexes only increase... we cannot allocat sids monotonically at the client and then send them disordered... --- CMakeLists.txt | 2 +- lib/roles/h2/http2.c | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e4d0051a..aca07f048 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -327,7 +327,7 @@ set(PACKAGE "libwebsockets") set(CPACK_PACKAGE_NAME "${PACKAGE}") set(CPACK_PACKAGE_VERSION_MAJOR "4") set(CPACK_PACKAGE_VERSION_MINOR "0") -set(CPACK_PACKAGE_VERSION_PATCH "4") +set(CPACK_PACKAGE_VERSION_PATCH "5") set(CPACK_PACKAGE_RELEASE 1) set(CPACK_GENERATOR "RPM") set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") diff --git a/lib/roles/h2/http2.c b/lib/roles/h2/http2.c index 850380c03..659da9bee 100644 --- a/lib/roles/h2/http2.c +++ b/lib/roles/h2/http2.c @@ -316,10 +316,13 @@ lws_wsi_h2_adopt(struct lws *parent_wsi, struct lws *wsi) #endif wsi->h2.initialized = 1; +#if 0 + /* only assign sid at header send time when we know it */ if (!wsi->mux.my_sid) { wsi->mux.my_sid = nwsi->h2.h2n->highest_sid; nwsi->h2.h2n->highest_sid += 2; } +#endif lwsl_info("%s: binding wsi %p to sid %d (next %d)\n", __func__, wsi, (int)wsi->mux.my_sid, (int)nwsi->h2.h2n->highest_sid); @@ -2329,14 +2332,16 @@ lws_h2_client_handshake(struct lws *wsi) lwsl_debug("%s\n", __func__); - nwsi->h2.h2n->highest_sid_opened = sid; - if (!wsi->mux.my_sid) - wsi->mux.my_sid = sid; - else { - lwsl_debug("%s: %p already sid %d\n", - __func__, wsi, wsi->mux.my_sid); - //assert(0); - } + /* + * We MUST allocate our sid here at the point we're about to send the + * stream open. It's because we don't know the order in which multiple + * open streams will send their headers... in h2, sending the headers + * is the point the stream is opened. The peer requires that we only + * open streams in ascending sid order + */ + + wsi->mux.my_sid = nwsi->h2.h2n->highest_sid_opened = sid; + lwsl_info("%s: wsi %p: assigning SID %d at header send\n", __func__, wsi, sid); lwsl_info("%s: CLIENT_WAITING_TO_SEND_HEADERS: pollout (sid %d)\n", __func__, wsi->mux.my_sid);