Skip to content

Did WiFiClient.connected recently change for small payloads? #5257

Closed
@marcelstoer

Description

@marcelstoer

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-WROOM-2
  • Core Version: 2..4.2
  • Development Env: Arduino IDE
  • Operating System: macOS

Settings in IDE

  • Module: ESP-WROOM-2
  • Flash Mode: qio
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: ck
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: other

Problem Description

This is a follow-up to ThingPulse/esp8266-weather-station#140 which in turns follows up on as long thread in our support forum.

It appears that a (nested) HTTP/TCP parse loop that first checks for client.connected() and then for client.available() > 0 no longer works reliably for small payloads.

What seems to be happening on the networking stack is that "sometimes" the WiFiClient reports connected() == false immediately when the payload is sufficiently small. However, even though the client is no longer connected its internal buffer contains all the data and, hence, client.available() returns more than 0.

Can you confirm that such a double nested loop, which is a very common sketch template, should these days be changed to only check for client.available() > 0?

Sketch fragment

    // WiFiClient * client = http.getStreamPtr();
    // or something like
    // BearSSL::WiFiClientSecure client;
    // ...
    // if (client.connect(host, port))
    while(client.connected()) {
      while((size = client.available()) > 0) {
        // client->read() and do stuff
        // ...
        // give WiFi and TCP/IP libraries a chance to handle pending events
        yield();
      }
    }
  }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions