From 3a406f804e09b1a8a7024018e33d5671d069182b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Villac=C3=ADs=20Lasso?= Date: Tue, 25 Aug 2020 11:48:00 -0500 Subject: [PATCH] Explicitly close socket after response has entered finished state In at least two places in the code, the response object is evaluated on whether it has finished sending data to the client. If the response has already finished, or enters the finished state after sending data, the underlying socket should not be left open. Failure to close the socket in these scenarios cause the remote client to timeout expecting more data unless it closes the connection on its own. Fixes: #802 --- src/WebRequest.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/WebRequest.cpp b/src/WebRequest.cpp index bbce5ca..35fd7dc 100644 --- a/src/WebRequest.cpp +++ b/src/WebRequest.cpp @@ -189,8 +189,16 @@ void AsyncWebServerRequest::_removeNotInterestingHeaders(){ void AsyncWebServerRequest::_onPoll(){ //os_printf("p\n"); - if(_response != NULL && _client != NULL && _client->canSend() && !_response->_finished()){ - _response->_ack(this, 0, 0); + if(_response != NULL && _client != NULL && _client->canSend()){ + if(!_response->_finished()){ + _response->_ack(this, 0, 0); + } else { + AsyncWebServerResponse* r = _response; + _response = NULL; + delete r; + + _client->close(); + } } } @@ -199,10 +207,13 @@ void AsyncWebServerRequest::_onAck(size_t len, uint32_t time){ if(_response != NULL){ if(!_response->_finished()){ _response->_ack(this, len, time); - } else { + } + if(_response->_finished()){ AsyncWebServerResponse* r = _response; _response = NULL; delete r; + + _client->close(); } } }