electronicsguy / ESP8266

ESP8266 Projects
242 stars 183 forks source link

GET/POST requests will get stuck if connection loss #53

Closed biank88 closed 6 years ago

biank88 commented 6 years ago

https://github.com/electronicsguy/ESP8266/blob/0e3edc3390056793d5ef48f4c95d1bd30c83e589/HTTPSRedirect/HTTPSRedirect.cpp#L320

// Skip any empty lines
  do{
    line = readStringUntil('\n');
}while(line.length() == 0);

Problem The number of empty lines has no bound, in particular, an empty line might be created as a result of a timeout during a connection loss.

enindza commented 6 years ago

Yes, it seems like that loop is a problem. Connection lost will stuck program in that loop if the router is disconnect only during execution of client->POST (didn't test with GET). Adding timeout seems to help.

  uint32_t timeout_ms = 950; 
  uint32_t t = millis(); 
  do{ 
    line = readStringUntil('\n'); 
  }while(millis() - t < timeout_ms and line.length() == 0);

950ms timeout will not do much since it will still have to wait for readStringUntil default timeout.

electronicsguy commented 6 years ago

Thanks for this. I'll test it more on my side and update as needed.