Repository: godotengine/godot (language: cpp)

Issue:
[4.4.dev5] Websockets stuck in STATE_CLOSING
### Tested versions

Starting with 4.4.dev5
Confirmed to work with 4.4.dev4

### System information

Godot v4.4.dev5 - Windows 10.0.26100 - Multi-window, 2 monitors - OpenGL 3 (Compatibility) - AMD Radeon RX 6700 XT (Advanced Micro Devices, Inc.; 32.0.12033.1030) - Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz (6 threads)

### Issue description

Client WebSocketPeers get stuck on STATE_CLOSING when close() is called.

### Steps to reproduce

- Download MRP with any Godot version >= 4.4.dev5
- Click on "Client disconnect"
- Check output

### Minimal reproduction project (MRP)

[100948.zip](https://github.com/user-attachments/files/18277136/100948.zip)



Discussion / hints:

Fix patch:
diff --git a/modules/websocket/wsl_peer.cpp b/modules/websocket/wsl_peer.cpp
index 9ffc343571e8..f50b4c480652 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 {


Test patch: