Skip to content

Fix the 3.6.0 boot loop: don't call LwIP for an unconnected client before the network starts - #131

Merged
willmmiles merged 2 commits into
ESP32Async:mainfrom
kedube:before-network
Nov 14, 2026
Merged

willmmiles merged 2 commits into
ESP32Async:mainfrom
kedube:before-network

Conversation

@kedube

@kedube kedube commented Nov 14, 2026 •

Copy link
Copy Markdown

Since 3.6.0, a sketch that uses an AsyncClient before the network has started asserts at boot and restarts forever. The usual case is AsyncMqttClient: its constructor calls setNoDelay(true), so a global AsyncMqttClient crashes before setup() 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 for tcpip_api_call() to post to:

Arduino 2.0.14:  assert failed: tcpip_api_call IDF/components/lwip/lwip/src/api/tcpip.c:497 (Invalid mbox)
Arduino 3.1.1:   assert failed: xQueueSemaphoreTake queue.c:1709 (( pxQueue ))
                 ... sys_mutex_lock ← tcp_core_guard ← AsyncClientImpl::setNoDelay

Three calls on a client that was never connected now reach lwIP:

  • setNoDelay() and setKeepAlive() take the core lock before looking for a pcb. 3.5.0's setNoDelay() returned first when there was none.
  • ~AsyncClient() always calls close(), which always calls tcpip_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:

  1. setNoDelay() and setKeepAlive() 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.
  2. close() and abort() return first when _dispose_owed isn't set. lwIP only holds a pcb, lookup or event of the client while it is, and unlike _pcb it's also set during a lookup. abort() then returns ERR_CONN, as _tcp_abort() does when there's nothing to abort.

The mock lwIP gets a not_started fault: while it's set, tcpip_api_call() and the core lock are counted in calls_before_start(), since each would assert on a target. test_start.cpp has a test for each commit.

Testing

  • Native suite, all four environments (native, native-asan, native-no-ipv6, native-no-core-locking):

    • On 3.6.0, the new setter test fails with 4 calls into lwIP before it started.
    • With only the first commit, the close/abort/destructor test fails with 3.
    • With both commits, all 333 tests pass, and the same 8 known failures as before are skipped.
    • pre-commit passes.
  • 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():

    Before lwIP starts 3.6.0 Commit 1 Both
    setNoDelay(true) asserts ok ok
    setKeepAlive(1000, 3) asserts ok ok
    destroying the client asserts asserts ok

    The results were the same on both cores. After esp_netif_init(), all three were fine in every build. -Wall -Wextra adds 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:

#include <AsyncTCP.h>

void setup() {
  static AsyncClient client;
  client.setNoDelay(true);  // asserts: Wi-Fi hasn't started lwIP
}

void loop() {}

🤖 Generated with Claude Code

Comment thread src/AsyncTCP.cpp Resolved
Comment thread src/AsyncTCP.cpp Resolved
kedube and others added 2 commits November 13, 2026 23:23
…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>
@willmmiles
willmmiles merged commit 1a0165a into ESP32Async:main Nov 14, 2026
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants