Repository navigation
Description
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_levelcounts iterations; this loop yields ~1 ms per turn, so a wall-clock deadline may fit better. Butawait()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
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix(autoresearch): stop three coroutine RPCs wedging an RP board unti…
fix(autoresearch): stop three coroutine RPCs wedging an RP board unti…
fix(task): bound fl::platforms::await() so an unresolvable promise re…