From 46acd74a086c59a48b25af6522c596b40a8d7632 Mon Sep 17 00:00:00 2001 From: Quentin Sabah Date: Sun, 17 Nov 2019 12:22:06 +0100 Subject: [PATCH] Fix infinite loop when a Websocket connection is closed by client without closing handshake. --- src/HTTPConnection.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/HTTPConnection.cpp b/src/HTTPConnection.cpp index 83d2fae..a8b75a2 100644 --- a/src/HTTPConnection.cpp +++ b/src/HTTPConnection.cpp @@ -563,8 +563,15 @@ void HTTPConnection::loop() { HTTPS_LOGD("Calling WS handler, FID=%d", _socket); _wsHandler->loop(); } + + // If the client closed the connection unexpectedly + if (_clientState == CSTATE_CLOSED) { + HTTPS_LOGI("WS lost client, calling onClose, FID=%d", _socket); + _wsHandler->onClose(); + } + // If the handler has terminated the connection, clean up and close the socket too - if (_wsHandler->closed()) { + if (_wsHandler->closed() || _clientState == CSTATE_CLOSED) { HTTPS_LOGI("WS closed, freeing Handler, FID=%d", _socket); delete _wsHandler; _wsHandler = nullptr;