Skip to content

SimpleMDNS in combination with WiFiClient leads to panic #2650

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

Closed
GUVWAF opened this issue Nov 30, 2024 · 2 comments · Fixed by #2653
Closed

SimpleMDNS in combination with WiFiClient leads to panic #2650

GUVWAF opened this issue Nov 30, 2024 · 2 comments · Fixed by #2653
Labels
bug Something isn't working waiting for feedback Requires response from original poster

Comments

@GUVWAF
Copy link
Contributor

GUVWAF commented Nov 30, 2024

Using a Pico W (RP2040), SimpleMDNS in combination with WiFiClient leads to a panic due to an assert in LWIP:

sys_timeout: timeout != NULL, pool MEMP_SYS_TIMEOUT is empty

Here’s a MCVE:

#include <Arduino.h>
#include <WiFi.h>
#include <SimpleMDNS.h>

void setup() {
  Serial.begin(115200);
  delay(5000);
  WiFi.begin("ssid", "psk");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  Serial.println("Starting MDNS service");
  MDNS.begin("test");
  MDNS.addService("http", "tcp", 80);
  
  WiFiClient client;
  Serial.println("Connecting...");
  client.connect("www.google.com", 80);
}

void loop() {
  delay(1000);
  Serial.println("...");
}

It happens both for core version 4.2.1 and 4.3.0. When replacing SimpleMDNS with LEAmDNS, this works.

I found a reference to this error here: raspberrypi/pico-sdk#1281. So I bumped LWIP_DNS from 1 to 2 in lwipopts.h and recompiled libpico, and then the MCVE works. However, I'm not sure if this is a suitable fix or we should find out why SimpleMDNS needs more timers than LEAmDNS.

@earlephilhower
Copy link
Owner

Thanks for the MCVE and report. I actually posted in that thread because we had this kind of issue when SDK 1.5.0 came out.

The SimpleMDNS/.local PR tried to increase the needed buffers, but evidently it's not enough. Let me read up and see if there's a more direct way of increasing the timeouts than bumping that DNS value. Worst case, we can use that.

What's going on is the while LWIP stack uses its own internal scheduling system (MEMP_TIMEOUT) and not any external timers, and space for them all needs to be statically allocated. LeaMDNS is just another LWIP client and no different than any other connection so it's not using those internal timers directly.

In my testing I used ArduinoOTA (since I didn't have anything else that needed MDNS) but it uses UDP only. So, no need for a TCP retransmit timeout and there were enough timers. Here, you have a TCP connection as well as MDNS so we need add'l timeouts...

earlephilhower added a commit that referenced this issue Nov 30, 2024
Bump up the LWIP_ARP setting to increase the LWIP timeout pool to
avoid a panic when using SimpleMDNS and TCP clients.

Fixes #2650
@earlephilhower earlephilhower added bug Something isn't working waiting for feedback Requires response from original poster labels Nov 30, 2024
@earlephilhower
Copy link
Owner

In the PR I just bumped up the placeholder we were using to increase timeouts for other reasons (1.5.0 SDK, etc.). It should be a little lower memory than setting up 2 DNS request buffers (which in the Arduino case can't ever actually use but one) but it's the same idea, increase LWIP's internal MEMP_NUM_SYS_TIMEOUT without actually changing any LWIP files...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working waiting for feedback Requires response from original poster
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants