Repository navigation
Description
A WLED sync master should reject notification broadcasts to itself within a short period after sending out the broadcast.
This works as expected on 8266. However in arduino-esp32, WiFiUDP has a different behaviour and the sync master will stop receiving further notifications after the first self-adressed broadcast was rejected. So instead of just returning, the "early reject" path needs to remove the not yet parsed packet explicitly with notifierUdp.flush() (V4 builds) or notifierUdp.clear() (V5 builds).
On 8266, the flush() method does something completely different. So the fix must be guarded with #ifdef ARDUINO_ARCH_ESP32.
I've verified and confirmed the behaviour in arduino-esp32 v2.0.18. Not sure if the V5 builds (arduino-esp32 v3.0.x) are affected, too.
(this ticket was created from a sub-topic in #5924 (comment))
Analysis by the rabbit
Overview
The current 16_x branch still rejects self-originated notifications before consuming the packet at Line 522:
if (!isSupp && notifierUdp.remoteIP() == localIP) return;In stock 2.0.17, WiFiUDP::parsePacket() returns zero while rx_buffer exists. If a returned broadcast reaches this check, WLED retains the packet and stops draining that socket until something reads, flushes, or closes it.
This can retain one Arduino receive buffer and fill the underlying receive queue.
[....]
I've verified this behavior in both stock Arduino-ESP32 2.0.17 and Tasmota Arduino-ESP32 2.0.18:
parsePacket()stores a received packet inrx_buffer.- The self-originated-packet guard returns without consuming that buffer.
- On subsequent calls,
parsePacket()returns0becauserx_bufferstill exists. It does not callrecvfrom().
Thus, WLED stops processing new packets from notifierUdp until the current buffer is discarded or fully read, or the socket is stopped. The network stack can still queue incoming packets until its receive queue fills. This does not block sending or reception on the other UDP sockets.
The guard should discard the rejected packet:
if (!isSupp && notifierUdp.remoteIP() == localIP) {
notifierUdp.flush();
return;
}In these versions, flush() deletes the current receive buffer. It does not discard all packets queued in the socket. The next parsePacket() call can receive the next queued packet.
This confirms a receive-processing defect. It does not, by itself, establish the cause of the continuing heap loss.
Details
Code Analysis
ESP32: parsePacket() returns 0 when a previous packet was not consumed completely
If the master receives its own notification and the source IP matches Network.localIP(), the guard at Line 522 returns without consuming the packet.
In both Arduino-ESP32 2.0.17 and Tasmota 2.0.18, parsePacket() then returns 0 while that unread receive buffer exists. Therefore:
- The master stops processing all subsequent incoming packets on
notifierUdp, not just its own packets. - The master can still send notifications.
- The supplemental notification socket and RGB socket can still process packets.
- Reception on
notifierUdpresumes if code consumes or discards the buffer, or closes and reopens the socket.
A receive-only client does not trigger this self-packet condition. It can therefore continue processing notifications. However, another unread-packet guard, such as the oversized-packet guard, can also stall that client.
Sending alone does not trigger the stall. The device must receive a packet that reaches the early-return guard. Broadcast delivery and the source-IP comparison determine whether that happens.
So the defect can accidentally produce the “master sends, clients receive” behavior you describe. But it is not a reliable master-mode mechanism. It also prevents legitimate incoming control on that socket.
ESP8266: parsePacket() discards the previous packet
In ESP8266 Arduino Core 3.1.2:
WiFiUDP::parsePacket()calls_ctx->next().UdpContext::next()discards the previously exposed packet, including unread data.- It advances to the next queued packet, if one exists.
Thus, after WLED rejects its own notification, the next parsePacket() call discards that notification and continues reception. The ESP8266 master does not become receive-disabled through this guard.
Important correction to my previous recommendation
flush() is not portable receive-buffer cleanup:
| Framework | WiFiUDP::flush() behavior |
|---|---|
| ESP32 2.0.17 / Tasmota 2.0.18 | Deletes the current receive buffer. |
| ESP8266 3.1.2 | Calls endPacket(); it does not discard the received packet. |
My earlier notifierUdp.flush() recommendation applies to the inspected ESP32 frameworks only. A shared WLED fix must account for this difference, or explicitly read and discard the rejected packet.
You are interacting with an AI system.
Activity
softhack007 commentedon Oct 23, 2026
@coderabbitai
mainfor other "early return" WiFiUDP receivers that miss to flush the receive buffer.coderabbitai commentedon Oct 23, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 72366
🏁 Script executed:
Length of output: 47774
🏁 Script executed:
Length of output: 16079
🏁 Script executed:
Length of output: 21601
🏁 Script executed:
Length of output: 4870
🏁 Script executed:
Length of output: 4626
@softhack007Yes. V5 builds are affected by the same receive-buffer stall. I also found two additional affected receivers inmain.I inspected
mainat3cdb5108b924ec26dec81d2c92962b70b185bd01. These are source-analysis results, not hardware-test results.1. V5 / Arduino-ESP32 3.x
I checked these framework versions:
parsePacket()with an unread buffer0clear()deletes the buffer.flush()does nothing.0clear()deletes the buffer.flush()delegates toclear().0In these versions,
WiFiUDPmaps toNetworkUDP. A fullread()releases the receive buffer. A partialread()leaves the remaining bytes buffered.Therefore, the self-broadcast return at
wled00/udp.cpp, Line 520 also stalls V5 reception onnotifierUdp.Use
clear()for Arduino-ESP32 3.x. Do not rely onflush()across all 3.0.x versions.Sources: 3.0.0 implementation, 3.0.7 implementation, Tasmota implementation.
Note:
mainnow defaults to Tasmota 3.3.8.260506, rather than 3.0.x, inplatformio.ini, Line 323. That version remains affected.2. Other affected receive paths in
mainA. Hyperion / raw RGB: early returns leave the whole packet unread
Location:
wled00/udp.cpp, Line 499 and Line 500.After
rgbUdp.parsePacket()receives a packet:receiveDirectis false, the first return retains the packet.Either case blocks subsequent reception on
rgbUdp. EnablingreceiveDirectlater does not remove the retained buffer.The return for
realtimeOverrideis safe for this issue. It occurs after the full packet read.B. NTP: a partial read retains an extended response
Location:
wled00/ntp.cpp, Line 311.ntpUdp.read(pbuf, NTP_PACKET_SIZE);NTP_PACKET_SIZEis 48. If a response contains more than 48 bytes, this read leaves its tail buffered. This can happen with NTP extension fields or authentication data.The tail remains whether validation rejects the response or accepts it.
The existing cleanup does not recover from this state:
parsePacket() > 0.cb > 0.parsePacket()returns0, so both cleanup paths skip it.Discard the remaining receive buffer immediately after reading the 48-byte header, before any validation return.
C. Legacy Artemis receiver: a partial read retains excess payload
Location:
usermods/Artemis_reciever/usermod.cpp, Line 23–29.The receiver reads two header bytes, then at most
strip.getLengthTotal() * 3payload bytes.If the packet contains more payload than the configured LED count requires, unread bytes remain. Subsequent
UDP.parsePacket()calls return0.This is another partial-read defect, rather than an unconditional early-return defect. Discard the remaining packet after the bounded payload read.
Checked paths that do not have this stall
receiveAudioData()skips exactly five-byte packets internally. However, its caller discards the buffer whenever the function returns false. Seeaudio_reactive.cpp, Line 1629–1635. No persistent stall through the current caller.AsyncUDP, not thisWiFiUDPreceive-buffer mechanism.Oversized-packet guards: conditional concern only
Line 519 also returns without consuming an oversized notification from either notifier socket. Line 500 does the same for oversized RGB packets.
However, the inspected ESP32 3.x implementations cap received data at 1460 bytes, below WLED’s 1472-byte limit. Those oversized branches are therefore not reachable with these implementations. They should still discard the selected socket’s packet if a framework with a larger receive limit makes them reachable.
For the confirmed paths, retain the ESP32-only cleanup guard: use
flush()for V4 andclear()for V5. Do not apply ESP32 receive-cleanup semantics to ESP8266.You are interacting with an AI system.
softhack007 commentedon Oct 23, 2026
coderabbitai commentedon Oct 23, 2026
softhack007 commentedon Oct 23, 2026
@coderabbitai please find all other issue tickets that potentially have the same cause.
coderabbitai commentedon Oct 23, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 201656
🏁 Script executed:
Length of output: 48705
🏁 Script executed:
Length of output: 201978
🏁 Script executed:
Length of output: 67388
🏁 Script executed:
Length of output: 41075
@softhack007I searched open and closed issues for UDP, sync, Hyperion/HyperHDR, NTP, and receive-buffer cleanup. The best additional candidates are#3745and#163. Several other tickets deserve a check, but none establishes the same cause yet.Strongest candidates
#3745— ESP32 Sync is not working · Closed#163— Deactivating UDP realtime while hyperion.ng sending data causes WLED to hang · ClosedreceiveDirect == falserejection path. The reported web-server hang is broader than the socket stall alone explains.#1037— WLED WiFi fails when/win&RD=0command sent to it · ClosedThe age of
#163and#1037is relevant. Both predate the framework upgrade in WLED 16.0.0. They support investigating a longstanding cleanup defect, rather than assuming a new Arduino-ESP32 2.x requirement.Weaker candidates
#4404— 0.15.0 sync issues · Closed#4981— Sync not working in 0.15.1 or 0.16 nightly, but works in 0.14.4 · Closed#5619— Incorrect “relay off” handling when controlled by HyperHDR · OpenSimilar reports that I would keep separate
#5709and#4498— AP-mode sync failures: These describe failure from the AP master to its clients. In#4498, the reverse direction works. Blocking the master’s receive socket does not directly explain failure of its outgoing notifications.#5575— HyperHDR delay: Reports include continued reception with seconds of delay, including DDP. This differs from a persistentWiFiUDPreceive-buffer stall.#5510and#5705— Missing effect options or colors: Other fields still synchronize. These point to state-application defects, not a socket that stops receiving all packets.#4408— Audio sync stops after 260 seconds: The router-specific timing and successful operation with other routers support a multicast-membership problem. The current audio receiver also has caller-side cleanup.#3535and#3680— Hyperion stop/restart failures: These have reported fixes in later firmware.#3680was fixed through#3731. Similar symptoms do not establish a shared cause.#3672— Crash during UDP streaming: The discussion identifies a short-packet arithmetic underflow and confirms that guarding it removes the crash.#5924— Sync-send heap loss: This is the source ticket for#5929, but the receive-buffer defect does not establish the cause of continuing heap loss.I found no convincing additional NTP or Artemis ticket for the partial-read defect. The inspected NTP reports mainly concern ESP8266, incorrect timestamps, or time-zone handling.
Recommended verification order
Start with
#3745, then#163, then the unresolved ESP32 cases in#4404.For each affected
WiFiUDPsocket:parsePacket()call.available()immediately afterward.parsePacket()repeatedly returns0whileavailable()stays positive, discard the retained packet once.That test would distinguish the cleanup defect from configuration, broadcast delivery, and live-mode state problems.
This is the candidate list from the searches and discussions I inspected. It is not a confirmed duplicate list, and keyword searches cannot guarantee that every indirectly described report was found.
You are interacting with an AI system.
[-]WLED SYNC broadcast: master device blocks itself from receiving any sync messages until reboot (ESP8266 not affected)[/-][+]WLED UDP broadcast: master device blocks itself from receiving any new messages until reboot (ESP8266 not affected)[/+]softhack007 commentedon Oct 23, 2026
@coderabbitai does
AsyncUDPrequire the same cleanup guards, or can it handle unparsed messages gracefully?coderabbitai commentedon Oct 23, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 57291
@softhack007No. ESP32AsyncUDPdoes not need the same receive-cleanup guards. A callback can reject a packet with an earlyreturn, without reading its payload. The framework releases the packet buffer after the callback returns.I checked Arduino-ESP32 1.0.6, 2.0.17, and 3.0.7. All three use the same ownership mechanism:
AsyncUDP::_recv()creates anAsyncUDPPacketand calls the registered callback.pbuf_free()._recv()releases the framework’s remaining buffer reference.Packet copies use reference counting. Cleanup does not depend on how many payload bytes the callback reads.
Sources: 1.0.6 receive path, 2.0.17 receive path, and 3.0.7 receive path.
Details
Effect on WLED
WLED’s
ESPAsyncE131::parsePacket()accesses the payload through_packet.data(). It does not drain the packet withread(). That is valid for this API.WiFiUDPAsyncUDPflush()Do not add
WiFiUDP-style cleanup guards to the E1.31 / Art-Net / DDP callbacks for this issue. Do not manually free the framework-owned payload.Two separate constraints still apply:
packet.data().Thus, an ignored or partially parsed packet does not cause the same unread-buffer stall. This does not guarantee that malformed packets are safe for WLED’s parser; packet-length validation remains a separate requirement.
These conclusions come from source inspection, not hardware tests.
You are interacting with an AI system.
coderabbitai commentedon Oct 23, 2026
[-]WLED UDP broadcast: master device blocks itself from receiving any new messages until reboot (ESP8266 not affected)[/-][+]UDP SYNC broadcast: master device blocks itself from receiving any new messages until reboot (ESP8266 not affected)[/+]esp32: always flush WiFiUDP rx buffer on early exit
[-]UDP SYNC broadcast: master device blocks itself from receiving any new messages until reboot (ESP8266 not affected)[/-][+]UDP SYNC broadcast: master device can block itself from receiving any new messages until reboot (ESP8266 not affected)[/+]