Skip to content

Commit

Permalink
Remove deadlock when server is not acking our data (#6107)
Browse files Browse the repository at this point in the history
* Use bounded waiting instead of infinite one to avoid deadlock

* Reduce timeout to fail much sooner if server is not acking our data

* Return timeout to 15 seconds on every disconnect

* Add comment to introduced delay to make it super clear
  • Loading branch information
sislakd authored and d-a-v committed May 19, 2019
1 parent 2b7846d commit 912c0db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ void WiFiClientSecure::_freeSSL() {
_recvapp_len = 0;
// This connection is toast
_handshake_done = false;
_timeout = 15000;
}

bool WiFiClientSecure::_clientConnected() {
Expand Down Expand Up @@ -1009,6 +1010,9 @@ bool WiFiClientSecure::_connectSSL(const char* hostName) {
_x509_insecure = nullptr;
_x509_knownkey = nullptr;

// reduce timeout after successful handshake to fail fast if server stop accepting our data for whathever reason
if (ret) _timeout = 5000;

return ret;
}

Expand Down
3 changes: 2 additions & 1 deletion libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ class ClientContext
}

_send_waiting = true;
esp_yield();
// This delay will be interrupted by esp_schedule on next received ack
delay(_timeout_ms);
} while(true);
_send_waiting = false;

Expand Down

0 comments on commit 912c0db

Please sign in to comment.