Skip to content

Commit f80b961

Browse files
authored
Merge pull request fhessel#58 from quentin/ws-lost-issue
Fix infinite loop when a Websocket connection is lost
2 parents 4e66fe5 + 46acd74 commit f80b961

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/HTTPConnection.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,15 @@ void HTTPConnection::loop() {
563563
HTTPS_LOGD("Calling WS handler, FID=%d", _socket);
564564
_wsHandler->loop();
565565
}
566+
567+
// If the client closed the connection unexpectedly
568+
if (_clientState == CSTATE_CLOSED) {
569+
HTTPS_LOGI("WS lost client, calling onClose, FID=%d", _socket);
570+
_wsHandler->onClose();
571+
}
572+
566573
// If the handler has terminated the connection, clean up and close the socket too
567-
if (_wsHandler->closed()) {
574+
if (_wsHandler->closed() || _clientState == CSTATE_CLOSED) {
568575
HTTPS_LOGI("WS closed, freeing Handler, FID=%d", _socket);
569576
delete _wsHandler;
570577
_wsHandler = nullptr;

0 commit comments

Comments
 (0)