Skip to content

random crashes (ESP32-C5) when changing from 2.4Ghz to 5Ghz Wi-Fi (same network name) #5945

In progress

Description

@softhack007

I've experienced random crashes on a -C5 when changing the Wi-Fi band from "both" to "5Gz".

WLED seems to reconnect (with the same network credentials), then shows a crash dump on serial monitor. After a reboot, the 5Ghz connection works and WLED continues to run without crashing again.

From the debug stack trace, it seems to be a problem related to mDNS - maybe we should stop mDNS before connecting to another Wi-Fi band.

Initial connect or forced reconnect (@ 223s).
WiFi: Default SSID (WLANxxxxx) used.
initConnection() called @ 223s.
WiFi disconnect.
WiFi-E: Disconnected! @ 223s
WiFi-E: STA Stopped
WiFi-E: Event 100
getWLEDHostname: 'wled-cf18c8'
WiFi mode_null: driver teardown / re-init.
WiFi-E: driver ready.
WiFi-E: STA Started
Access point disabled (init).

Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.

Core  0 register dump:
MEPC    : 0x42093c1a  RA      : 0x420a07c4  SP      : 0x40822870  GP      : 0x40810604  
TP      : 0x40822910  T0      : 0x4209eb0a  T1      : 0x40809b24  T2      : 0xffffffff  
S0/FP   : 0x00000001  S1      : 0x00000000  A0      : 0x00000000  A1      : 0x00000000  
A2      : 0x00000001  A3      : 0x408228d0  A4      : 0x00000001  A5      : 0x00000000  
A6      : 0x00000004  A7      : 0x4081c000  S2      : 0x408285ec  S3      : 0x00000001  
S4      : 0x4082b234  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000  
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
T3      : 0x4081c000  T4      : 0x00000001  T5      : 0x4081532c  T6      : 0x00000006  
MSTATUS : 0x00001881  MTVEC   : 0x40800003  MCAUSE  : 0x00000005  MTVAL   : 0x000000e8  
MHARTID : 0x00000000 

rebooting...
ESP-ROM:esp32c5-eco2-20250121
Build:Jan 21 2025
rst:0xc (SW_CPU),boot:0x18 (SPI_FAST_FLASH_BOOT)
Core0 Saved PC:0x40808bbe

Stack Trace

Nr Address Function Location
0 0x42093c1a esp_netif_is_netif_up ??
1 0x420a07c4 join_group mdns_networking_lwip.c.obj
2 0x40810604 __global_pointer$ ??
3 0x4209eb0a mdns_priv_get_esp_netif ??
4 0x40809b24 ledc_hal_set_hpoint ??
5 0x40800003 _vector_table ??
6 0x4208d58a sys_arch_mbox_fetch ??
7 0x420a0986 pcb_if_init_lwip mdns_networking_lwip.c.obj
8 0x4207d566 tcpip_thread tcpip.c.obj
9 0x408107c4 __global_pointer$ ??
10 0x40810774 __global_pointer$ ??
11 0x40810774 __global_pointer$ ??
12 0x4085e6f0 _stack_sentry ??

Registers

MEPC 0x42093c1a esp_netif_is_netif_up at ??:?
RA 0x420a07c4 join_group at mdns_networking_lwip.c.obj:?
SP 0x40822870
GP 0x40810604
TP 0x40822910
T0 0x4209eb0a mdns_priv_get_esp_netif at ??:?
T1 0x40809b24 ledc_hal_set_hpoint at ??:?
T2 0xffffffff

Activity

  1. changed the title [-]ESP32-C5 crsh when changing from 2.4Ghz to 5Ghz Wi-Fi (same network name)[/-] [+]ESP32-C5 crash when changing from 2.4Ghz to 5Ghz Wi-Fi (same network name)[/+] on Nov 1, 2026
  2. added this to the 17.0 milestone on Nov 1, 2026
  3. Esmail-sarhadi commented on Nov 2, 2026

    @Esmail-sarhadi

    The ordering theory fits the trace: WiFi mode_null: driver teardown / re-init runs while mDNS is still up, and the mdns task holds a pointer to the netif that the teardown frees. On the C5 the mdns task and the wifi task share a core, so the free can land between select() returning and the service task using the pointer - a load access fault at a low address, which is what the dump shows.

    The order that avoids it:

    MDNS.end();                 // stops the task and joins it
    WiFi.disconnect(true);      // or WiFi.mode(WIFI_OFF) when the band changes
    // ... reconnect
    MDNS.begin(hostname);       // after the new IP is up

    MDNS.end() in the ESP32 core calls mdns_free() and waits for the task to exit. mdns_free() on its own - which is what the disconnect path gives you - does not join the task, so the pointer can still be in use when the netif goes away.

    To confirm it is the ordering and not the band switch before changing anything: add a handler for ARDUINO_EVENT_WIFI_STA_DISCONNECTED that calls MDNS.end() and nothing else, then repeat the 2.4 -> 5 GHz switch. If the crash disappears, the pointer lifetime is the cause and the fix is the explicit ordering above.

    For the general case, checking MDNS.begin()'s return value after every reconnect turns a silent failure into a log line, which matters more than usual here because the crash happens after the reconnect has already been reported as successful.

  4. softhack007 commented on Dec 2, 2026

    @softhack007
    MemberAuthor

    There are some open ends listed in #5965

    • we might need to stop UDP listeners before Wi-Fi driver tear-down
    • a broader analysis contributed by @DedeHai:

      @softhack007 I had minimax analyze this as well. I am not familiar enough with the network code to judge it, but here is the full analysis.

      wled-mdns-crash-analysis.md

      edit: this is the (probably a bit overboarding) patch it suggested, not sure if it builds on top of this PR or main as I did not check any of it. Could contain useful fixes or just a bunch of AI overly-cautios guards.

      wled-mdns-crash-fix.patch

  5. added this to the 16.1.x bugfixes milestone on Dec 2, 2026
  6. changed the title [-]ESP32-C5 crash when changing from 2.4Ghz to 5Ghz Wi-Fi (same network name)[/-] [+]random crashes (ESP32-C5) when changing from 2.4Ghz to 5Ghz Wi-Fi (same network name)[/+] on Dec 2, 2026
  7. softhack007 commented on Dec 2, 2026

    @softhack007
    MemberAuthor

    @coderabbitai please summarize the remining open ends from #5964, including the assessment in #5945 (comment)

  8. coderabbitai commented on Dec 2, 2026

    @coderabbitai
    Contributor
    Analysis chain

    Script executed:

    #!/bin/bash
    set -u
    repo=wled/WLED
    echo '=== ISSUE OR PR 5964 ==='
    gh api "repos/$repo/issues/5964" --jq '{number,title,state,html_url,created_at,updated_at,body,pull_request}' || true
    echo '=== PR 5964 DETAILS ==='
    gh api "repos/$repo/pulls/5964" --jq '{number,title,state,merged,merged_at,html_url,body,head: .head.sha,base: .base.ref}' || true
    echo '=== ISSUE COMMENTS 5964 ==='
    gh api --paginate "repos/$repo/issues/5964/comments?per_page=100" --jq '.[] | {id,user:.user.login,created_at,updated_at,html_url,body}' || true
    echo '=== PR REVIEWS 5964 ==='
    gh api --paginate "repos/$repo/pulls/5964/reviews?per_page=100" --jq '.[] | {id,user:.user.login,state,submitted_at,html_url,body}' || true
    echo '=== PR REVIEW COMMENTS 5964 ==='
    gh api --paginate "repos/$repo/pulls/5964/comments?per_page=100" --jq '.[] | {id,user:.user.login,created_at,updated_at,html_url,path,line,original_line,body,in_reply_to_id}' || true
    echo '=== LINKED ISSUE COMMENT ==='
    gh api "repos/$repo/issues/comments/7353807027" --jq '{id,user:.user.login,created_at,updated_at,html_url,issue_url,body}' || true
    echo '=== LINKED ISSUE 5945 ==='
    gh api "repos/$repo/issues/5945" --jq '{number,title,state,html_url,body}' || true
    echo '=== ANALYSIS ATTACHMENT ==='
    curl -L -fsS --max-time 30 'https://github.com/user-attachments/files/35469954/wled-mdns-crash-analysis.md' || true
    echo '=== PATCH ATTACHMENT (SUMMARY ONLY) ==='
    curl -L -fsS --max-time 30 'https://github.com/user-attachments/files/35497892/wled-mdns-crash-fix.patch' | grep -E '^(Subject:|diff --git|@@|[+-][^+-])' | head -200 || true

    Length of output: 60949


    Script executed:

    #!/bin/bash
    set -u
    repo=wled/WLED
    echo '=== PR 5965 ==='
    gh api "repos/$repo/pulls/5965" --jq '{number,title,state,merged,merged_at,updated_at,html_url,body,head:.head.sha,base:.base.ref}' || true
    echo '=== PR 5965 ISSUE COMMENTS ==='
    gh api --paginate "repos/$repo/issues/5965/comments?per_page=100" --jq '.[] | select(.user.login | test("bot";"i") | not) | {id,user:.user.login,created_at,updated_at,html_url,body}' || true
    echo '=== PR 5965 REVIEWS ==='
    gh api --paginate "repos/$repo/pulls/5965/reviews?per_page=100" --jq '.[] | select(.user.login | test("bot";"i") | not) | {id,user:.user.login,state,submitted_at,html_url,body}' || true
    echo '=== PR 5965 REVIEW COMMENTS ==='
    gh api --paginate "repos/$repo/pulls/5965/comments?per_page=100" --jq '.[] | {id,user:.user.login,created_at,updated_at,html_url,path,line,body,in_reply_to_id}' || true
    echo '=== ISSUE 5945 COMMENTS ==='
    gh api --paginate "repos/$repo/issues/5945/comments?per_page=100" --jq '.[] | select(.user.login | test("bot";"i") | not) | {id,user:.user.login,created_at,updated_at,html_url,body}' || true
    echo '=== PR 5965 DIFF ==='
    gh api -H 'Accept: application/vnd.github.v3.diff' "repos/$repo/pulls/5965" || true

    Length of output: 38342


    Script executed:

    #!/bin/bash
    set -u
    echo '=== TECHNICAL BOT RESPONSES ON PR 5965 ==='
    gh api --paginate 'repos/wled/WLED/issues/5965/comments?per_page=100' | python3 -c '
    import json,sys,re,html
    data=json.load(sys.stdin)
    for c in data:
     if "bot" not in c["user"]["login"].lower(): continue
     b=c.get("body") or ""
     if not re.search(r"UDP|ntpUdp|teardown|AsyncTCP",b,re.I): continue
     old=None
     while old!=b:
      old=b
      b=re.sub(r"<details\b[^>]*>(?:(?!<details\b).)*?</details>","",b,flags=re.I|re.S)
     b=re.sub(r"<!--.*?-->","",b,flags=re.S)
     b=html.unescape(b)
     b=re.sub(r"\n{3,}","\n\n",b).strip()
     print("\n---",c["html_url"],c["created_at"],"---\n",b[:20000])
    ' || true
    echo '=== RELATED AP ISSUE ==='
    gh api 'repos/wled/WLED/issues/5709' --jq '{number,title,state,html_url,updated_at,body}' || true
    echo '=== POSSIBLE UDP FOLLOW-UPS ==='
    gh search issues 'repo:wled/WLED "notifier2Udp" crash' --limit 20 --json number,title,state,url,updatedAt || true

    Length of output: 15510


    @softhack007 The mDNS work appears to be in #5965, rather than #5964. #5965 is merged; #5964 concerns the Wi-Fi list and WPA-Enterprise settings.

    Remaining network open ends

    1. Investigate the separate UDP crash. On a classic ESP32, reconnect tests found crashes in notifier2Udp.parsePacket() → lwip_recvfrom → pbuf_free with both the unmodified build and #5965. The cause is not established. Stopping UDP sockets before teardown is an experiment, not a confirmed fix.

    2. Coordinate UDP users and restart paths. Clearing connection flags can prevent later receive calls, but it does not close sockets or synchronize other tasks. A delay alone does not guarantee that other users have stopped. Compare the current behavior, flags-only, and synchronized stop-and-restart under UDP traffic. Check station reconnect, changed IP, AP fallback, UDP sync, RGB input and NTP. See the UDP assessment and follow-up.

    3. Investigate the potential NTP race. The time-settings handler and the loop task can both call ntpUdp.begin(). The flag does not serialize them. This race has not been reproduced or linked to the notifier crash. See the NTP analysis.

    4. Check other network services. E1.31 multicast, async Art-Net, MQTT, captive-portal DNS, and active HTTP/WebSocket clients need assessment across teardown and recovery. There is no established requirement to stop AsyncWebServer before teardown. Shared AP and station services need particular care. See the service assessment.

    5. Investigate AP-mode UDP sync separately. #5709 may involve broadcast addressing rather than socket restart. A packet capture is needed to distinguish those possibilities.

    6. Complete validation. The reported S3 and classic ESP32 tests saw no recurrence of the mDNS crash with #5965. A physical C5 band-switch test, mDNS answers after reconnect, and the enabled ArduinoOTA path were still untested in the PR discussion. Repeat the S3 regression tests for any UDP changes.

    Broader assessment from #5945

    The linked analysis proposes a stale-netif lifetime issue as the mDNS crash mechanism. It also raises possible follow-ups: check MDNS.begin() and service-registration results, assess hostname sanitization and runtime name changes, review shared ArduinoOTA/mDNS ownership, and examine blocking MDNS.queryHost() calls.

    These are proposals to verify, not established causes of the reported crash. The accompanying patch was shared without build or applicability verification. The analysis also did not establish the exact resolved mDNS component version or legacy-build behavior.

    For the actual #5964, the remaining stated test gap is a real WPA-Enterprise login. The PR notes that esp32dev needs CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT=y to compile that feature.


    Learnings used

    Learnt from: CR
    Repo: wled/WLED PR: 0
    File: CONTRIBUTING.md:0-0
    Timestamp: 2026-10-31T16:42:25.881Z
    Learning: Applies to wled00/data/index.css : Applicability reference:
    AGENTS.md: # AGENTS.md — WLED AI Coding Agent & AI Code Review Reference
    ## Required User Agreement
    ### No agent-posted replies or issues
    Reviewer time is limited, and checking long AI-generated explanations for reasoning errors and hallucinations is costly. Even after the user agreement is confirmed:
    
    - Creating or updating pull requests remains allowed (after the user agreement is confirmed). Keep PR descriptions concise and factual, and include a summary written by the user in their own words, leading with what they want to achieve or what bothers them in plain language, as described in [CONTRIBUTING.md](CONTRIBUTING.md#opening-issues--feature-requests).
    
    Source excerpt:
    # Thank you for making WLED better!
    
    ## Coding Guidelines
    
    ### Code style
    
    #### Indentation
    
    We use tabs for indentation in Web files (.html/.css/.js) and spaces (2 per indentation level) for all other files.  
    You are all set if you have enabled `Editor: Detect Indentation` in VS Code.
    

    You are interacting with an AI system.

  9. Tycorc commented on Dec 3, 2026

    @Tycorc

    @softhack007 for the open end "stop UDP listeners before the Wi-Fi teardown": I tested both variants from #5965 (#5965 (comment)) on the classic ESP32 and the ESP32-S3 from my earlier test, on c70cbe8 (same tree as main after the merge). Each reconnect is forced after a fresh boot by a /settings/wifi save that only changes the BSSID, with sync packets to port 65506 at 10 Hz.

    UDP crashes / reconnects ESP32 ESP32-S3
    unpatched 85/100 79/100
    unpatched, after factory reset 49/50 44/50
    flags cleared + delay(250) 5/5 5/5
    flags cleared + stop() before the teardown 0/100 0/100
    same, after factory reset 0/50 0/50
    • Flags + delay only moves the crash: initInterfaces() -> notifier2Udp.begin() -> stop() -> close() -> netconn_drain -> pbuf_free -> esp_pbuf_free. So a stop() after the teardown crashes too, it has to come before WiFi.disconnect().
    • With stop() before the teardown all 300 reconnects came back without a reboot, and UDP sync (21324, 65506) and raw RGB worked after each one. mDNS answered again in 10 of 10.
    • The change is in Stop WiFiUDP sockets before the Wi-Fi teardown (follow-up to #5965) #6026, with the steps to reproduce the test.
    • NTP: I also moved ntpUdp.begin() from the time settings handler in set.cpp into handleNetworkTime(). NTP still syncs. I never got a crash from that begin() without the patch, so this part is not proven.
    • UDP Sync between two esp32 does not work in AP mode #5709 is unchanged: AP only, master -> slave 0 of 6, slave -> master 6 of 6.

    Not tested: sending during the reconnect (sync send and node broadcast were off), espalexaUdp and fftUdp (WiFiUDP too, not stopped by the block, not open here), the AsyncUDP receivers, ESP8266, C5, ArduinoOTA. 3 more patched attempts aborted on an HTTP timeout in my script, no crash.

    If u need more details or logs, let me know.

    Patch and tests were AI-assisted.

  10. added
    in progress
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugin progress

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions