Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WiFiClient] Default connection timeout, when no timeout provided #5487

Merged
merged 2 commits into from
Aug 2, 2021
Merged

[WiFiClient] Default connection timeout, when no timeout provided #5487

merged 2 commits into from
Aug 2, 2021

Conversation

cziter15
Copy link
Contributor

@cziter15 cziter15 commented Aug 1, 2021

The problem

WiFiClient's connect method variant where no timeout is passed can block esp32 MCU and may then cause watchdog to kick in and reset the device. This behavior is different from that, what is in arduino-esp8266 core.

Summary

Some cross-esp libraries (working both on esp32 and 8266), like PubSubClient simply call connect method on WiFiClient, to get connected to remote server. However, connect behavior varies betwen esp arduino 8266 and esp arduino 32 cores. This pull request tries introduce same behavior - to make connect method non-blocking on esp32, like it is with 8266 arduino core.

Proposed solution

Introduce default fixed timeout that can be changed by #define - by default set to 3 seconds.

Affected components:

WiFiClient

Affected methods:

int connect(IPAddress ip, uint16_t port);
int connect(const char *host, uint16_t port);

Impact

May impact projects or libraries using connect method variant without specified timeout, where:

  • remote is located far away or
  • connection is heavily limited, or
  • remote is slow, when it comes to accept the connection

@CLAassistant
Copy link

CLAassistant commented Aug 1, 2021

CLA assistant check
All committers have signed the CLA.

@me-no-dev me-no-dev merged commit be84c82 into espressif:master Aug 2, 2021
@me-no-dev
Copy link
Member

Thanks @cziter15 !

@cziter15 cziter15 deleted the patch-1 branch August 2, 2021 13:25
@cziter15
Copy link
Contributor Author

cziter15 commented Aug 2, 2021

You're welcome :)

My project heavily bases on esp-arduino, visit in the meantime:
https://github.com/cziter15/ksIotFrameworkLib

That's why I'm digging in esp32 Arduino core too.

@NUTSDADDY
Copy link

Use WiFiClient connecting to server always failed until set timeout to 3s
connect(IPAddress ip, uint16_t port, int32_t timeout)

me-no-dev pushed a commit that referenced this pull request Aug 11, 2021
## Summary
#5487 introduced a default timeout for WiFiClient, however the default was specified in milliseconds instead of seconds, see be84c82#commitcomment-54358731
This 3ms timeout breaks OTA when the processor is busy.

## Impact
Sets the default to a saner value, fixes OTA.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants