mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-10-26 22:10:45 +00:00
[HttpClientLight] Time out reading a body when the server goes silent
writeToStreamDataBlock() waited for the rest of a body for as long as connected() held. A server that stops sending part way through a body without closing the connection leaves connected() true, so getString() never returned and the unit stopped responding. Give up after _tcpTimeout without data and return HTTPC_ERROR_READ_TIMEOUT, as handleHeaderResponse() already does. Same fix as arendst/Tasmota#25139.
This commit is contained in:
1 file changed
+10
@@ -1376,6 +1376,10 @@ int HTTPClientLight::writeToStreamDataBlock(Stream * stream, int size)
|
||||
uint8_t * buff = (uint8_t *) malloc(buff_size);
|
||||
|
||||
if(buff) {
|
||||
// a server gone silent without closing stays connected(): give up
|
||||
// after _tcpTimeout without data, as handleHeaderResponse() does
|
||||
unsigned long lastDataTime = millis();
|
||||
|
||||
// read all data from server
|
||||
while(connected() && (len > 0 || len == -1)) {
|
||||
|
||||
@@ -1448,8 +1452,14 @@ int HTTPClientLight::writeToStreamDataBlock(Stream * stream, int size)
|
||||
len -= readBytes;
|
||||
}
|
||||
|
||||
lastDataTime = millis();
|
||||
delay(0);
|
||||
} else {
|
||||
if((millis() - lastDataTime) > _tcpTimeout) {
|
||||
log_w("read timeout after %d bytes", bytesWritten);
|
||||
free(buff);
|
||||
return HTTPC_ERROR_READ_TIMEOUT;
|
||||
}
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user