Repository navigation
Fix the 3.6.0 boot loop: don't call LwIP for an unconnected client before the network starts - #131
Merged
Merged
Conversation
willmmiles
requested changes
Nov 14, 2026
…nnection Since 3.6.0 they take the core lock before looking for a pcb. Libraries configure the client they hold from their constructor - AsyncMqttClient calls setNoDelay(true) - and a global one is constructed before setup() can start Wi-Fi, when LwIP has neither a core lock to take nor a thread for tcpip_api_call() to post to. So a sketch with a global AsyncMqttClient asserts at boot and restarts forever: Arduino 2.x: assert failed: tcpip_api_call ... (Invalid mbox) Arduino 3.x: assert failed: xQueueSemaphoreTake queue.c:1709 (( pxQueue )) With no pcb there's nothing to set, so return first, as _tcp_recved() does and as setNoDelay() did before 3.6.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
~AsyncClient() closes every client, and since 3.6.0 close() always calls into LwIP. But one that was never connected can be destroyed before the network has started, when LwIP can't be called: the same assert as in the last commit, on Arduino 2.x and 3.x. LwIP only holds a pcb, lookup or event of a client while _dispose_owed is set, so close() and abort() have nothing to do without it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kedube
force-pushed
the
before-network
branch
from
November 14, 2026 04:33
6d301c1 to
116d45a
Compare
willmmiles
approved these changes
Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since 3.6.0, a sketch that uses an
AsyncClientbefore the network has started asserts at boot and restarts forever. The usual case is AsyncMqttClient: its constructor callssetNoDelay(true), so a globalAsyncMqttClientcrashes beforesetup()has run. AsyncMqttClient asks for any AsyncTCP, so a fresh PlatformIO build picks up 3.6.0 without anyone changing anything.Before lwIP's
tcpip_init()has run (Wi-Fi does it), there is no core lock to take and no lwIP thread fortcpip_api_call()to post to:Three calls on a client that was never connected now reach lwIP:
setNoDelay()andsetKeepAlive()take the core lock before looking for a pcb. 3.5.0'ssetNoDelay()returned first when there was none.~AsyncClient()always callsclose(), which always callstcpip_api_call(). 3.5.0 only closed when there was a pcb. The comment there explains why 3.6.0 doesn't check: a lookup can bind a pcb after the caller has looked.The change
Two commits, so either can be taken alone:
setNoDelay()andsetKeepAlive()return first when there's no pcb, as_tcp_recved()already does. With no connection there's nothing to set, and during a lookup the locked check found no pcb either.close()andabort()return first when_dispose_owedisn't set. lwIP only holds a pcb, lookup or event of the client while it is, and unlike_pcbit's also set during a lookup.abort()then returnsERR_CONN, as_tcp_abort()does when there's nothing to abort.The mock lwIP gets a
not_startedfault: while it's set,tcpip_api_call()and the core lock are counted incalls_before_start(), since each would assert on a target.test_start.cpphas a test for each commit.Testing
Native suite, all four environments (
native,native-asan,native-no-ipv6,native-no-core-locking):pre-commitpasses.On an ESP32, Arduino 2.0.14 (IDF 4.4.6, no core locking) and Arduino 3.1.1 (IDF 5.3.2, core locking), a sketch tried each call before starting lwIP, then again after
esp_netif_init():setNoDelay(true)setKeepAlive(1000, 3)The results were the same on both cores. After
esp_netif_init(), all three were fine in every build.-Wall -Wextraadds no warnings.In real firmware: with both commits, an EleksTube IPS clock (AsyncMqttClient 0.9.0, ESPAsyncWebServer main) booted and served all its pages as before. It also got through two minutes of parallel downloads without restarting.
I haven't tried Arduino 3.3.x, which your CI builds, or LibreTiny.
Minimal reproduction, on Arduino 2 or 3:
🤖 Generated with Claude Code