TCPClient hangs up core

I seem to be running this issue with the current master of all three repos. My test application.cpp is included at the end of this post. After some amount of time the Core seems to crash. It crashes somewhere between Serial.println(" -- Connected -- "); and the Serial.print(c);, but I don’t know exactly where. That is also assuming there aren’t any cached prints that don’t make it out before crashing. When it crashed the /dev/ttyACM0 serial port i’m reading closes and the Core seems to restart based on the LED, but I never get a serial port again. In my DMESG I get

[25331.384033] usb 2-1.4: new full-speed USB device number 77 using ehci_hcd
[25331.478195] cdc_acm 2-1.4:1.0: This device cannot do calls on its own. It is not a modem.
[25331.478210] cdc_acm 2-1.4:1.0: ttyACM0: USB ACM device
[25678.241534] usb 2-1.4: USB disconnect, device number 77

If I press the RST button, I get the first three lines again and it runs for a similar amount of time.

I also seem to be having general issues with the TCPClient::connect() function. I’ve been getting a high number of failures to connect, in my tests it fails about 50% of the time. Out of 137 attempts to connect, it failed 861 times before crashing. It was in a Cyan Breathing the whole time.

I have the exact same loop() code running on an Arduino with Ethernet shield and I’m currently at 430 attempts and 1 failure.

When I run my much bigger app it crashes much more quickly. After about 4 to 15 attempts.

#application.cpp:

#include "application.h"

TCPClient client;
char server[] = "m2.exosite.com";

const unsigned long interval = 5*1000;  // delay between updates, in milliseconds
unsigned long failCounter = 0;
unsigned long totalFailCounter = 0;
unsigned long totalCounter = 0;

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println(" -- Stats -- ");
  Serial.print("    Attempts: ");
  Serial.println(totalCounter++);
  Serial.print("    Failures: ");
  Serial.println(totalFailCounter);
  if (client.connect(server, 80)) {
  	failCounter = 0;
    Serial.println(" -- Connected -- ");
    
    client.println("GET /timestamp HTTP/1.1");
    client.println("Host: m2.exosite.com");
    client.println("User-Agent: Spark/? Patrick/0");
    client.println("Connection: Close");
    client.println();
    
    while(!client.available());
    
    while(client.available()) {
      char c = client.read();
      Serial.print(c);
    }
    
    Serial.println();
    
    client.stop();
    
    delay(interval);
  } 
  else {
    Serial.println(" -- Connection Failed -- ");
    Serial.print("    Count: ");
    Serial.println(++failCounter);
    totalFailCounter++;
    client.stop();
    delay(500);
  }
}
1 Like