Skip to content

fl::platforms::await() polls unbounded — an unresolvable promise hangs the caller forever (wedges RP boards until the watchdog fires) #4369

Closed

Description

@zackees

fl::platforms::await() waits on a promise with no bound of any kind. When the promise cannot be resolved, the caller never returns. On a microcontroller that means the sketch stops, and the board only comes back when the watchdog resets it.

platforms/await.h:51

while (!promise.is_completed()) {
    promise.update();
    if (promise.is_completed()) break;
    runtime.suspendMainthread(1000);  // Yield ~1ms
}

No iteration cap, no deadline, no escape.

Its sibling already solves this

fl::task::await_top_level (fl/task/executor.h:199-230) guards the same wait twice:

int& await_depth = detail::await_depth_tls();
if (await_depth > 10) {
    return PromiseResult<T>(Error("await_top_level recursion limit exceeded - possible infinite loop"));
}
...
const int max_pump_iterations = 10000; // Safety limit
while (!p.is_completed() && pump_count < max_pump_iterations) { ... }
...
if (pump_count >= max_pump_iterations) {
    return PromiseResult<T>(Error("await_top_level timeout - promise did not complete"));
}

So this is not a request for a novel policy — the codebase already decided that an await which cannot complete should return an Error rather than spin, and PromiseResult<T> already carries that. platforms::await() just never got the same treatment.

Reproduced on hardware

Any platform selecting the null coroutine backend reaches it trivially, because the coroutine that would resolve the promise never runs. On an RP2350W (2DCB876B587EA334), calling a test that awaits:

testCoroutineAwait: null      <- no response
ping:               null      <- device no longer answering at all
status:             null

and it returns only after a reset:

{"message": "pong", "uptimeMs": 78827,
 "lastResetCause": "WATCHDOG", "lastResetWasWatchdog": true}

Three AutoResearch RPCs do this, each confirmed in isolation with a ping after it: testCoroutineAwait (4 await call sites), testCoroutineAwaitError (1), testCoroutineChainedAwait (2). #4367 declines those three on FL_IS_RP — that guards the symptom on one platform, not the hazard.

Why it is not RP-specific

A null backend is the easiest way to hit it, but not the only one. await() is documented for blocking on real async work — fl::task::await(fl::fetch_get(...)) in task.h:80. Any promise that never resolves and whose update() never errors hangs the caller the same way, on any platform. The null backend just makes it deterministic.

Suggested direction

Give platforms::await() the bound its sibling has, and return PromiseResult<T>(Error(...)) on exhaustion. Two things need an owner's judgement rather than my guess:

  • What bound. await_top_level counts iterations; this loop yields ~1 ms per turn, so a wall-clock deadline may fit better. But await() exists to block on genuinely slow work, so too tight a default breaks valid uses — which is exactly why I did not pick a number and change it myself.
  • Whether a null backend should refuse earlier. Arguably await() could fail immediately when the runtime cannot run coroutines. It should not do so unconditionally: promise.update() is called inside the loop, so a promise driven by polling rather than by a coroutine can legitimately complete.

Found while testing whether #3832's "null coroutine backend" claim had evidence behind it. Related: #4367 (RP-side guard), #3832, #4308.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions