From a1ef068b7769bfcfbf2551008fec92d33b0e6d7d Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 7 Oct 2024 02:01:03 +0200 Subject: [PATCH] [WebSocket] Better detect transition to STATE_CLOSING When wslay receives a message that is too big it automatically sends a close request to the remote peer with code 1009 (Message Too Big) but it also completely stop calling the receive callback resulting in the state being "stuck" as CONNECTED (even if both client and server have disconnected). We now check if we sent such a close message and manually transition to the "closed" state with the proper reason. --- modules/websocket/wsl_peer.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/websocket/wsl_peer.cpp b/modules/websocket/wsl_peer.cpp index 0c0a046805c..7099826c9c2 100644 --- a/modules/websocket/wsl_peer.cpp +++ b/modules/websocket/wsl_peer.cpp @@ -689,12 +689,22 @@ void WSLPeer::poll() { close(-1); return; } - if (wslay_event_get_close_sent(wsl_ctx) && wslay_event_get_close_received(wsl_ctx)) { - // Clean close. - wslay_event_context_free(wsl_ctx); - wsl_ctx = nullptr; - close(-1); - return; + if (wslay_event_get_close_sent(wsl_ctx)) { + if (wslay_event_get_close_received(wsl_ctx)) { + // Clean close. + wslay_event_context_free(wsl_ctx); + wsl_ctx = nullptr; + close(-1); + return; + } else if (wslay_event_get_status_code_sent(wsl_ctx) == WSLAY_CODE_MESSAGE_TOO_BIG) { + // wslay seems to completely stop processing incoming events after receiving a message that's too big. + close_reason = "Message Too Big"; + close_code = 1009; + wslay_event_context_free(wsl_ctx); + wsl_ctx = nullptr; + close(-1); + return; + } } } }