Repository navigation
Description
Problem
A WebSocket serial attach (AsyncSerialMonitor.__aenter__) sometimes fails with only ConnectionError: session closed. The daemon spends more than its 3 s open_port cap before it even opens the tty, sends an Error frame that says so, and the Python client discards that frame's text.
Seen from FastLED AutoResearch on an LPC845-BRK (LPC-Link2 CMSIS-DAP VCOM, /dev/ttyACM1, Linux, fbuild 2.5.51): 5 of 12 post-deploy bench attaches failed on 2026-11-17/18 (FastLED/FastLED#5271). The port did not re-enumerate (no cdc_acm / USB events in the kernel log during the runs), and the next attach a few seconds later succeeded.
Evidence
1. In both natural failures, the open started more than 3 s after the attach was pending
Daemon log (UTC):
07:30:50.126 Daemon staying alive: 1 pending serial attach
07:30:53.671 serial_manager: opening port ... /dev/ttyACM1 family=Some(CdcAcmBridge) <- no "opened"/failure ever logged
07:30:54.132 Daemon is idle; self-eviction in 30s
07:59:46.722 Daemon staying alive: 1 pending serial attach
07:59:50.072 serial_manager: opening port ... /dev/ttyACM1 family=Some(CdcAcmBridge) <- no "opened"/failure ever logged
07:59:50.738 Daemon is idle; self-eviction in 30s
The opening port line is emitted inside the spawn_blocking closure in fbuild-serial/src/manager.rs::open_port, after crate::boards::family_for_port() (which walks available_ports() plus sysfs health). In both failures it appears 3.35 s and 3.55 s after the attach was already pending. The await_ws_serial_open_port timeout (WS_SERIAL_OPEN_PORT_TIMEOUT = 3s, fbuild-daemon/src/handlers/websockets.rs) had therefore already fired: the async continuation was dropped (hence no port opened successfully line), and the handler returned (hence idle half a second later). In successful runs the same gap was 0.1 to 2.0 s, and the actual OS open took about 2 ms.
2. Idle attach latency is already a large fraction of the cap
115 back-to-back AsyncSerialMonitor attach/detach cycles on the same port, with the daemon idle or running one other board build: 0 failures, attach time min 0.11 s, median 0.29 to 0.53 s, max 1.85 s. Almost all of that is before the tty open (open itself is about 2 ms in the log).
3. The client hides the daemon's reason
fbuild-python/src/serial_session.rs, SerialSession::connect:
Ok(ServerMessage::Attached { message, .. }) => { return Err(ConnectionFailed(...)) }
_ => return Err(SessionError::Closed),The daemon's SerialServerMessage::Error { message: "open_port(/dev/ttyACM1) exceeded 3s; ..." } falls into _ and becomes "session closed".
4. Deterministic repro of the client symptom
Hold the tty with TIOCEXCL for 6 s (the daemon's open gets EBUSY and retries 250/500/1000/2000 ms), and attach meanwhile:
0 FAIL 3.312s ConnectionError: session closed
1 ok 1.757s
Asks
- Surface the daemon's
Errortext inSerialSession::connect(for example asConnectionFailed(message)), so the caller seesopen_port(...) exceeded 3s; <holder or wedged>instead ofsession closed. - Don't charge pre-open work to the 3 s cap. Either resolve the board family outside the timed region (or cache it per port), or apply the cap only to the OS open and its retries. A slow
available_ports()walk on a loaded host is not a wedged driver. - Optionally make the cap configurable or a few seconds longer. The client-side handshake is 5 s, so a 3 s daemon cap leaves the client no way to wait out a slow-but-healthy open.
FastLED adds a bounded client-side retry (3 attempts, 1 s apart, only for session closed / handshake timeout) until this is fixed. It will be removed once fbuild ships a fix.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
zackees commentedon Nov 18, 2026
Merged as
47e1a898(PR #2084, squash via merge queue, 2026-11-18T15:34:40Z).Ask 1 (surface the daemon's reason):
SerialSession::connectnow mapsServerMessage::Errorin the rejected-attachedposition toConnectionFailed("daemon rejected serial attach: …"), so callers seeopen_port(/dev/ttyACM1) exceeded 3s; …instead ofsession closed.Ask 2 (no pre-open work inside the cap):
SharedSerialManager::resolve_open_familyruns theavailable_ports()+sysfsfamily_for_port()walk inspawn_blockingbefore the timed open at both WS open sites (initial attach and post-deploy recovery), and the resolved family is passed explicitly, soWS_SERIAL_OPEN_PORT_TIMEOUTnow covers only the tty open and its retries (~2 ms in the logs above). Fallback isCdcAcmBridge, i.e. the same idle-DTR/RTS stateNoneproduced.Ask 3 (configurable/longer cap): deliberately not taken. With inference outside the timer the cap covers a 2 ms open, so widening it would only mask real driver wedges.
Tests: fbuild-serial lib 207p/0f/1i (new
resolve_open_family_is_total_and_bounded), fbuild-python lib 69p/0f (new fake-daemonattach_error_frame_surfaces_daemon_reason), fbuild-daemon lib 330p/0f/3i; fmt + clippy--all-targets --no-deps -D warningsclean. Usage count is unchanged — FastLED's 3-attempt client retry can be dropped whenever convenient, but nothing in fbuild requires it now.test(serial): move #2083 family tests to manager/tests/family.rs
fix(autoresearch): retry the fbuild serial attach that fails as "sess…
ci(fbuild): require fbuild 2.5.52, drop the LPC8xx core pin, retry on…