Skip to content

Commit 3a406f8

Browse files
committed
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: me-no-dev#802
1 parent f13685e commit 3a406f8

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/WebRequest.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,16 @@ void AsyncWebServerRequest::_removeNotInterestingHeaders(){
189189

190190
void AsyncWebServerRequest::_onPoll(){
191191
//os_printf("p\n");
192-
if(_response != NULL && _client != NULL && _client->canSend() && !_response->_finished()){
193-
_response->_ack(this, 0, 0);
192+
if(_response != NULL && _client != NULL && _client->canSend()){
193+
if(!_response->_finished()){
194+
_response->_ack(this, 0, 0);
195+
} else {
196+
AsyncWebServerResponse* r = _response;
197+
_response = NULL;
198+
delete r;
199+
200+
_client->close();
201+
}
194202
}
195203
}
196204

@@ -199,10 +207,13 @@ void AsyncWebServerRequest::_onAck(size_t len, uint32_t time){
199207
if(_response != NULL){
200208
if(!_response->_finished()){
201209
_response->_ack(this, len, time);
202-
} else {
210+
}
211+
if(_response->_finished()){
203212
AsyncWebServerResponse* r = _response;
204213
_response = NULL;
205214
delete r;
215+
216+
_client->close();
206217
}
207218
}
208219
}

0 commit comments

Comments
 (0)