Skip to content

Fix Timeout Bug in WebServer #2938

New issue

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

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

Already on GitHub? # to your account

Merged
merged 6 commits into from
Jul 9, 2019
Merged

Fix Timeout Bug in WebServer #2938

merged 6 commits into from
Jul 9, 2019

Conversation

vicatcu
Copy link
Contributor

@vicatcu vicatcu commented Jun 26, 2019

Take a look at this line of code

      if (_currentClient.available()) {
        if (_parseRequest(_currentClient)) {
          _currentClient.setTimeout(HTTP_MAX_SEND_WAIT); // <-- THIS LINE
          _contentLength = CONTENT_LENGTH_NOT_SET;
          _handleRequest();
          ...

Observe that HTTP_MAX_SEND_WAIT expands to 5000 (here)

Review the definition of setTimeout in WiFiClient class which subsequently passes the value to the Client class as follows

WiFiClient::setTimeout(uint32_t seconds) { // <-- NOT MILLISECONDS
    Client::setTimeout(seconds * 1000);    // <-- NOTICE x1000
    struct timeval tv;
    tv.tv_sec = seconds;
    ...

Solution is to divide it by 1000 in the call to setTimeout. Alternative solution would be to re-define the HTTP_MAX_SEND_WAIT to be defined in seconds instead of milliseconds, but that would be different from the surrounding defines, which is why I opted for the proposed implementation. The compiler should shake out the maths anyway.

@me-no-dev me-no-dev merged commit 02e5172 into espressif:master Jul 9, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants