arduino / arduino/ArduinoCore-mbed

Every 5th TCP connection fails on Arduino Giga R1 if we don't fully read the HTTP content sent from the server each time

Open
#937 31 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
411
Forks
225
PR merge metrics
No merged PRs in 30d

Description

Platform: Giga R1
Arduino Core Mbed 4.1.5
HttpClient: 0.6.1

Here's a sequence of events with a crudely instrumented MbedClient. We connect using ArduinoHttpClient every 1s. Every 5th connection fails with error -3005 from `static_cast(sock)->open(getNetwork());` in the `MbedClient::connect() call`. When it fails it takes 30s to return. This is in version 4.1.5. In version 4.1.1 it would never recover and continue to fail until device reboot. There would be no 30s delay. This issue occurs on any http server I've tried. I can continue to connect to the server in the code with python on my Mac with no problems. If I extend the delay so I connect to the server once every 5s the problem goes away. At 4s it reappears.

```
22:10:12.229 -> Fetching content length from httpforever.com:80
22:10:12.393 -> Return code from connect0
22:10:13.213 -> took=993ms length: 5124
22:10:15.229 -> Fetching content length from httpforever.com:80
22:10:15.394 -> Return code from connect0
22:10:16.216 -> took=979ms length: 5124
22:10:18.198 -> Fetching content length from httpforever.com:80
22:10:18.365 -> Return code from connect0
22:10:19.225 -> took=1008ms length: 5124
22:10:21.203 -> Fetching content length from httpforever.com:80
22:10:21.366 -> Return code from connect0
22:10:22.222 -> took=1004ms length: 5124
22:10:24.202 -> Fetching content length from httpforever.com:80
22:10:24.202 -> Return code from TCPSocket::open-3005
22:10:54.295 -> took=30099ms length: -1
```

code

```
#include
#include
#include

void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("HI");
// put your setup code here, to run once:
auto wifi = WiFiInterface::get_default_instance();
wifi->set_dhcp(true);
wifi->set_credentials("ZZZZ", "ZZZZ", nsapi_security_t::NSAPI_SECURITY_WPA2);
Serial.println(wifi->connect());
}

void loop() {
// put your main code here, to run repeatedly:
WiFiClient client;

HttpClient httpClient(client, "httpforever.com", 80);
Serial.println("Fetching content length from httpforever.com:80");
auto then = millis();
httpClient.beginRequest();
httpClient.get("/");
httpClient.endRequest();
auto len = httpClient.contentLength(); // Doesn't read all content
Serial.print("took="); Serial.print((millis() - then)); Serial.print("ms "); Serial.print("length: "); Serial.println(len);
delay(5000);
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the repeated request sequence in the provided sketch, then trace ArduinoHttpClient's contentLength() through MbedClient::connect() and static_cast(sock)->open(getNetwork()). Identify why leaving the HTTP content unread causes later connections to fail or wait 30 seconds. Done means repeated connections remain successful without the long timeout; no test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, cpp
Domain
embedded-iot, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.