Repository navigation
Description
Context
An ESP32-S3 link reached fbuild's fixed 300-second deadline and returned a terminal build failure, but a descendant ld process continued running and writing firmware.elf afterward. The project cannot safely retry into that output directory until the abandoned process finishes: the previous failed build still owns an output writer after fbuild has reported completion.
Observed during FastLED/FastLED#5001 hardware validation on Linux with fbuild 2.5.49+git.98affea702ff (98affea702ff58e551124cda68f863659acebb7c). The run used the stock daemon in a private DEV/cache configuration. The host was heavily loaded, so the deadline itself is not evidence of incorrect linker behavior or a compiler hang.
The affected downstream workflow was an AutoResearch run equivalent to:
bash autoresearch esp32s3_opi_psram8 --lcd --worker-core 1 \
--upload-port /dev/ttyACM1 --lanes 1 --strip-sizes 700 \
--frames 4 --timeout 3m --skip-lintThe AutoResearch timeout above governs monitoring; it does not change the linker subprocess deadline. The build/deploy phase ended with:
Running: .../.venv/bin/fbuild .../.build/fbuild/esp32s3_opi_psram8 deploy -e esp32s3_opi_psram8 -p /dev/ttyACM1
build error: timeout: command timed out after 300s
Deploy failed (fbuild) [860.4s]
BUILD+FLASH FAIL
The total duration includes compilation before linking. The live process tree observed for the link was:
compiler driver PID 204500
collect2 PID 204579
ld PID 204609
After the terminal timeout, ld PID 204609 remained alive. A later observation showed about 76 seconds of CPU time over 6m13s of wall time, consistent with a slow, scheduled linker rather than proof of a wedge. The ELF was observed at zero bytes while the orphan still held it, then grew to 15,177,316 bytes when that process eventually exited. No second linker was started against the same output until the previous writer was gone. This investigation did not kill processes, operate the board, or modify source.
Confirmed source path
Esp32Linker::linkpasses an explicitSome(Duration::from_secs(300))torun_command.wait_and_captureconsumes the Tokio child inwait_with_output(). Whentokio::time::timeoutexpires, it returnsFbuildError::Timeoutwithout terminating and reaping the descendant tree before returning.spawn_tokio_containedsupplies direct-child kill-on-drop and daemon owner-death containment. These are not a per-command descendant cleanup guarantee while the daemon remains alive.- The Linux containment setup creates a process group and sets a parent-death signal on the launched child, but the timeout path does not explicitly terminate/reap that command's group. The compiler driver's own descendants can therefore outlive the dropped direct child.
FBUILD_SUBPROCESS_DEFAULT_TIMEOUT_SECSaffects calls without an explicit deadline. The ESP32 link's explicit 300-second value wins, so changing that default is not an existing way to extend this link deadline.
Proposal
Give each owned subprocess invocation a cleanup boundary that includes its descendants. On timeout or cancellation, stop and reap that invocation's process tree, drain/close its output handling, and finish cleanup before releasing the project/build lock or sending the terminal failure response. Use the repository's process abstraction so Linux process groups and Windows containment follow the same ownership contract. Never terminate the daemon's entire compiler group or other clients' work.
Keep a bounded linker deadline. A separately configurable, validated ESP32 link deadline could accommodate slow/LTO-heavy hosts, but it must not substitute for cleanup: every configured timeout must leave no writers behind. Write failed outputs to a temporary path or otherwise invalidate them only after all owned writers have stopped; a late ELF must not become an apparently successful artifact.
Acceptance criteria
- RED -> GREEN: first add a focused hardware-free test using the production
run_commandpath. Its launcher must spawn a grandchild that keeps an output file/pipe open and attempts a delayed write after the timeout. Demonstrate the current escaped-descendant failure before implementing the fix. - After the fixed command returns timeout, every process owned by that command has exited and been reaped within a bounded cleanup budget, and no delayed write or further ELF mutation occurs.
- Cover timeout and cancellation, inherited stdout/stderr handles, and the Linux/Windows process-tree backends. Keep normal successful commands working.
- An unrelated concurrent command/build remains alive. A retry for the failed project's output directory begins only after the previous command's writers are gone, and cannot consume a partial or late-published ELF.
- Re-run an ESP32-S3 compiler-driver -> collect2 -> ld case under load with an intentionally short test deadline. Record the process tree before/after and stable output state after the terminal result.
- If a configurable link deadline is added, test its validation and precedence explicitly; keep default behavior bounded and document that the generic default-timeout environment variable does not override explicit call-site budgets.
Decisions
- The bug is abandoned process-tree/output ownership after timeout, not the fact that a heavily loaded host exceeded five minutes.
- Cleanup is per invocation and must finish before lock/response completion. No global process-name kills, daemon restarts, or client-side sleeps/retries are an acceptable fix.
- No hardware access is needed for the primary regression; the ESP32 link is end-to-end confirmation after the host process contract is fixed.
Related issues
- Daemon doesn't cancel in-flight builds when CLI is force-killed (zombie build processes) #853: historical client-disconnect cancellation work; this is a current explicit subprocess timeout with surviving descendants.
- fix(avr8js): test-emu hangs after stopping the nodejs-wheel launcher #1694 / fix(avr8js): resolve native Node before emulation #1697: emulator launcher termination previously left a native child holding inherited pipes; the linker case needs the shared subprocess ownership guarantee rather than an emulator-specific executable substitution.
- audit: blocking operations with no timeout in fbuild-build (sub-issue of #802) #809: the audit that introduced the explicit ESP32 link deadline.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
zackees commentedon Nov 3, 2026
Opened #1868 for the process-tree ownership half of this report:
platform::process::terminate_treestops the process group a contained childleads, and only when the kernel confirms that pid leads it — an uncontained
child that shares fbuild's own group can never take fbuild down.
wait_and_capture(captured) andrun_command_passthroughnow stop the treeand reap it before
FbuildError::Timeoutis returned, so a retry cannotbegin while an abandoned
ldstill ownsfirmware.elf.RED -> GREEN is a hardware-free
sh -cfork/detached-writer test on theproduction
run_commandpath (both writers survived before the change).Two items from this issue are deliberately not in #1868:
Job Object handle it creates, so
terminate_treedegrades to thesingle-process kill there. Needs the handle handoff.
cleanup, so it belongs in its own change.