Skip to content

Possible bug ESP8266WebServer::handleClient method #8941

Closed
@supersjellie

Description

@supersjellie

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: [ESP-12|ESP-01|
  • Core Version: 3.1.2
  • Development Env: [Arduino IDE]
  • Operating System: [Windows]

Settings in IDE

  • Module: [Generic ESP8266 Module|Nodemcu]
  • Flash Mode: [qio|dio|other]???
  • Flash Size: [4MB/1MB]
  • lwip Variant: [v1.4|]
  • Reset Method: [ck|nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mh]
  • Upload Using: [OTA|SERIAL]
  • Upload Speed: [115200

Problem Description

I've got an openHAB system and use five devices constructed with either an ESP01 or a NodeMCU (switches/sensors). openHAB communicates by calling and url and the ESP device returns a JSON string with the response. Usually working fast and stable BUT the openHAB log shows regular timeouts of the ESP's. This can also be reproduced by using a browser in developer mode. Refreshing usually takes 20-60 ms but frequently 1000-3000 ms responses OR 60.000 ms fails occur. The timeouts don't cause a reboot of the ESP, they keep running and the next call is usually succesfull.

I think the source of the issue is using a variable "client" to copy an object to "_currentClient". I'm no expert but learned to avoid this construction, something to do with the copy being a crippled version of the original object. Replacing the code at the start of the ESP8266WebServer-impl.h handleClient method (put it in sketch) to avoid this construction makes it stable for me. Quite simple, there seems not to be a real reason to use the client variable. Adjusted to use _currentClient from the start. Before this adjustment 1 to 10-20 of the calls produced timeout errors in the openHAB log. After this, they've completely gone (testperiod 24 hrs).

So maybe worth investigating. I also have ESP32 devices and they use the same code and also suffer the timeouts. I've not tested it yet, but maybe the same modification may apply here.

MCVE Sketch

void ESP8266WebServerTemplate<ServerType>::handleClient() {

 if (_currentStatus == HC_NONE) {
    //ClientType client = _server.accept();
    _currentClient= _server.accept();
    if (!_currentClient) {
      return;
    }

    DBGWS("New client\n");

    //_currentClient = client;
    _currentStatus = HC_WAIT_READ;
    _statusChange = millis();
        
  }

Debug Messages

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions