Skip to content

Commit 276ec45

Browse files
authored
Handle error triggered by closed sessions
From updateBuffer() a session clean up is initiated via closeConnection() if error is detected when reading from SSL but the already removed session is not handled in other parts of the state machine.
1 parent fea072d commit 276ec45

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/HTTPConnection.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ int HTTPConnection::updateBuffer() {
207207
} else {
208208
// An error occured
209209
_connectionState = STATE_ERROR;
210-
HTTPS_LOGE("An receive error occured, FID=%d", _socket);
210+
HTTPS_LOGE("An receive error occured, FID=%d, SSL_error=%d", _socket, readReturnCode);
211211
closeConnection();
212212
return -1;
213213
}
@@ -255,7 +255,7 @@ size_t HTTPConnection::readBuffer(byte* buffer, size_t length) {
255255

256256
size_t HTTPConnection::pendingBufferSize() {
257257
updateBuffer();
258-
258+
if (isClosed()) return 0;
259259
return _bufferUnusedIdx - _bufferProcessed + pendingByteCount();
260260
}
261261

@@ -589,11 +589,15 @@ void HTTPConnection::loop() {
589589
}
590590

591591
// If the handler has terminated the connection, clean up and close the socket too
592-
if (_wsHandler->closed() || _clientState == CSTATE_CLOSED) {
593-
HTTPS_LOGI("WS closed, freeing Handler, FID=%d", _socket);
594-
delete _wsHandler;
595-
_wsHandler = nullptr;
596-
_connectionState = STATE_CLOSING;
592+
if (_wsHandler != nullptr){
593+
if (_wsHandler->closed() || _clientState == CSTATE_CLOSED) {
594+
HTTPS_LOGI("WS closed, freeing Handler, FID=%d", _socket);
595+
delete _wsHandler;
596+
_wsHandler = nullptr;
597+
_connectionState = STATE_CLOSING;
598+
}
599+
} else {
600+
HTTPS_LOGI("WS closed due to SSL level issue and cleanded up");
597601
}
598602
break;
599603
default:;

0 commit comments

Comments
 (0)