From 81181c594170057612eb1bf3224858a474f19722 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sat, 18 Jan 2025 15:54:38 +0100 Subject: [PATCH] [WS] Fix peer stuck in CLOSING state This was due by the buffer being cleared on close (including in closing state) preventing further reads. This commit changes the close logic to only clear the buffer when the peer connection has been fully closed (acknowledged by the other end, or closed due to a "broken" connection). --- modules/websocket/wsl_peer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/websocket/wsl_peer.cpp b/modules/websocket/wsl_peer.cpp index 9ffc343571e..f50b4c48065 100644 --- a/modules/websocket/wsl_peer.cpp +++ b/modules/websocket/wsl_peer.cpp @@ -860,10 +860,12 @@ void WSLPeer::close(int p_code, String p_reason) { } } - heartbeat_waiting = false; - in_buffer.clear(); - packet_buffer.resize(0); - pending_message.clear(); + if (ready_state == STATE_CLOSED) { + heartbeat_waiting = false; + in_buffer.clear(); + packet_buffer.resize(0); + pending_message.clear(); + } } IPAddress WSLPeer::get_connected_host() const {