Skip to content

fix(daemon): timeout WebSocket serial opens - #983

Merged
zackees merged 1 commit into
mainfrom
fix/977-ws-open-timeout
Jul 6, 2026
Merged

fix(daemon): timeout WebSocket serial opens#983
zackees merged 1 commit into
mainfrom
fix/977-ws-open-timeout

Conversation

@zackees

@zackees zackees commented Jul 6, 2026

Copy link
Copy Markdown
Member

Summary

  • wrap WebSocket serial attach open_port(...) in a 30 second timeout matching HTTP monitor/deploy monitor behavior
  • send a serial error frame on timeout/error and return from the WebSocket handler so the socket closes and the pending attach guard drops
  • add regression coverage with an injected hung open future proving the timeout error and pending attach cleanup

Closes #977

Verification

  • soldr --no-cache cargo test --target-dir target-codex-977-nocache -p fbuild-daemon --no-default-features handlers::websockets -j 2 (captured pass: 8 passed)
  • soldr --no-cache cargo check --target-dir target-codex-977-nocache -p fbuild-daemon --no-default-features -j 2
  • soldr cargo fmt --all --check
  • git diff --check

Note: after the captured focused test pass, I made a readability-only cleanup in the test helper and re-ran soldr cargo fmt --all --check plus git diff --check; repeated no-cache/cached test capture attempts after that cleanup exceeded the local tool timeout while compiling or left orphaned Cargo wrappers, so I stopped the orphaned verification process tree.

Summary by CodeRabbit

  • Bug Fixes

    • WebSocket serial attach now times out if opening a port takes too long, instead of waiting indefinitely.
    • Users now get a clearer error message when the serial port can’t be opened in time, including a helpful explanation and deadline details.
    • If the open attempt times out, the connection sends an error response and cleans up pending attach state properly.
  • Tests

    • Added coverage for timeout handling and cleanup behavior during serial attach.

Wrap the WebSocket serial attach open_port await in the same 30s hard deadline used by the HTTP monitor paths so a wedged USB driver cannot leave pending_serial_attaches stuck.

Add regression coverage with an injected hung open future to prove the timeout error and pending attach guard cleanup.

Closes #977
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 07611cd3-244f-4fe4-97c2-7dee09370125

📥 Commits

Reviewing files that changed from the base of the PR and between 3cbc49d and 3956201.

📒 Files selected for processing (2)
  • crates/fbuild-daemon/src/handlers/websockets.rs
  • crates/fbuild-daemon/src/handlers/websockets_tests.rs

📝 Walkthrough

Walkthrough

Adds a WS_SERIAL_OPEN_PORT_TIMEOUT (30s) constant and helper functions wrapping the WebSocket serial attach open_port call in tokio::time::timeout, replacing the unbounded await with a timeout-bounded version that sends an error frame on failure. Adds regression tests for timeout behavior and pending-attach cleanup.

Changes

WebSocket serial open_port timeout

Layer / File(s) Summary
Timeout helper and constant
crates/fbuild-daemon/src/handlers/websockets.rs
Adds Future import, WS_SERIAL_OPEN_PORT_TIMEOUT (30s) constant, format_timeout_for_error, and await_ws_serial_open_port to wrap open_port futures with tokio::time::timeout.
Attach handler wiring
crates/fbuild-daemon/src/handlers/websockets.rs
Replaces the direct open_port(...).await call in the attach path with await_ws_serial_open_port(...), using its formatted error string while preserving the error-frame send/early-return behavior.
Timeout and pending-attach cleanup tests
crates/fbuild-daemon/src/handlers/websockets_tests.rs
Adds tokio tests confirming await_ws_serial_open_port times out with a descriptive error, and that the pending-attach guard clears pending-attach count/info and busy_reason after a timeout.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant WebSocketHandler
  participant SerialManager

  Client->>WebSocketHandler: Attach message
  WebSocketHandler->>SerialManager: open_port(port, baud, client_id) with 30s timeout
  alt open_port completes
    SerialManager-->>WebSocketHandler: Ok/Err result
  else timeout elapses
    SerialManager-->>WebSocketHandler: (no response)
    WebSocketHandler-->>Client: SerialServerMessage::Error (timeout)
  end
  WebSocketHandler->>WebSocketHandler: drop pending-attach guard
Loading

Related issues: #977 (direct)

Suggested labels: daemon, websockets, timeout

Suggested reviewers: none identified

🐰 A timer ticks while ports awaken slow,
Thirty seconds granted, then the plug must go,
Guards drop quietly, counts return to naught,
No more wedged whispers where the daemon's caught.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/977-ws-open-timeout

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit 4f999cd into main Jul 6, 2026
90 of 93 checks passed
@zackees
zackees deleted the fix/977-ws-open-timeout branch July 6, 2026 07:15
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

daemon: timeout WebSocket serial open_port pending attaches

1 participant