Skip to content

fix(daemon,cli): tell slow-under-load apart from hung; queue deploys for a busy port - #2143

Merged
zackees merged 4 commits into
mainfrom
fix/load-tolerant-daemon-requests
Nov 22, 2026
Merged

zackees merged 4 commits into
mainfrom
fix/load-tolerant-daemon-requests

Conversation

@zackees

@zackees zackees commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Problem

On a heavily loaded host (load ~250-1100 on 16 cores, several agents building concurrently), FastLED's fbuild deploy -e esp32c6 failed in two ways:

  1. After 535 s: daemon error: request failed: error sending request for url (http://127.0.0.1:24318/api/deploy).
  2. After a 494 s build: serial error: port /dev/ttyACM1 is in use: deploy (project ...) by request ... for 35s, which threw the build away.

Root causes (from ~/.fbuild/prod/daemon/daemon.log)

  1. Self-eviction during a running build. OperationGuard::drop stored false into the shared operation_in_progress flag on every drop. With two concurrent operations, the first one to finish cleared it, and the idle loop logged Daemon is idle; self-eviction in 30s while [20/36] compiled [fastled] was still running, then Self-eviction triggered. The listener closed, new CLIs spawned daemons that hit root-owner.lock busy, the old daemon was SIGTERMed with in_flight=1, and the surviving client's request died.
  2. Fixed wall-clock request caps. Long requests carried a 30 min reqwest deadline, so slow-under-load and hung looked the same.
  3. No queueing for a busy port. preempt_for_deploy failed as soon as another request held the port.

Fix

  • OperationGuard clears the flag/state only when the last concurrent operation drops. busy_reason() also counts active and admitted operations. Self-eviction now goes through try_begin_shutdown(false), which closes admission atomically with the final busy check.
  • Progress-based liveness, following soldr's inactivity watchdog (soldr#2974: measure silence, not elapsed time). /api/daemon/info gains progress_seq. It is bumped by every work tracing event (compile steps, library builds, installs, deploy/flash, zccache compile handling) and by operation start/finish. Daemon housekeeping is excluded (the idle loop's once-a-minute staying alive, health, shutdown, zccache maintenance), so a hang still looks like a hang. The CLI (deploy, build, build_streaming, test-emu, install-deps) samples it every 10 s. It keeps waiting while the counter advances and fails only after a stall window of 600 s (FBUILD_DAEMON_STALL_SECS), scaled by load average per CPU and clamped to 1x-16x. The error names the stalled stage. A daemon without the counter keeps the old 30 min cap. The transport ceiling is 24 h, only to guard against a lost socket.
  • Busy port queueing. A deploy waits for a port held by another deploy/reset for up to 900 s (FBUILD_DEPLOY_PORT_WAIT_SECS; 0 restores fail-fast). A Notify wakes it as soon as the holder releases. While it waits, current_operation reads waiting for <port> (Ns so far): port ... is in use: deploy (project ...) by request ..., and the CLI prints each stage change.

Tests (RED against main, GREEN here)

  • finishing_one_operation_keeps_daemon_busy_while_another_runs: on main, busy_reason() is None after the first of two guards drops.
  • slow_but_progressing_operation_outlasts_old_fixed_timeout: a paused-clock run of 2x the old 30 min cap succeeds.
  • stalled_operation_fails_with_clear_error_naming_stage: fails about one stall window after the last progress, and the error names the stage.
  • high_load_extends_the_stall_window, stage_changes_are_reported, legacy_daemon_without_counter_uses_the_old_ceiling.
  • busy_port_is_waited_on_then_acquired, busy_port_wait_is_bounded_and_names_the_holder (tracker), deploy_waits_for_busy_port_then_acquires_it (serial manager).
  • housekeeping_events_do_not_count_as_progress, note_progress_advances_the_counter.

Release

Also bumps the version to 2.5.53 (Cargo.toml, pyproject.toml, Cargo.lock, uv.lock) so release-auto.yml can be dispatched on the merge commit.

…for a busy port

Three failures seen on a host at load ~250 (16 cores at times >1000):

1. Self-eviction mid-build. OperationGuard cleared the shared
   operation_in_progress flag on every drop, so when one of two
   concurrent operations finished the idle loop saw an "empty" daemon,
   self-evicted while the other client was still compiling, and that
   client failed after ~535 s with "error sending request for url
   .../api/deploy". The flag now clears only when the last operation
   drops, busy_reason() also counts active/admitted operations, and
   self-eviction closes admission atomically (try_begin_shutdown) before
   shutting down.

2. Fixed wall-clock request caps. Long daemon requests (deploy, build,
   test-emu, install-deps, streaming build) carried a 30 min reqwest
   deadline. They now wait on a progress-based watchdog in the soldr
   style (measure silence, not elapsed time): the daemon exposes a
   progress_seq counter on /api/daemon/info, bumped by every work
   tracing event (housekeeping such as the idle loop's "staying alive"
   is excluded so a hang still looks like a hang) and by operation
   start/finish. The CLI keeps waiting while it advances and fails only
   after a stall window (default 600 s, FBUILD_DAEMON_STALL_SECS) scaled
   by load average per CPU (clamped 1x..16x), naming the stalled stage.
   A daemon without the counter keeps the old 30 min cap.

3. Busy port failed instantly. A deploy whose port another request's
   deploy/reset held failed with "port ... is in use" and threw away a
   finished ~500 s build. It now queues for the port up to 900 s
   (FBUILD_DEPLOY_PORT_WAIT_SECS), woken as soon as the holder
   releases, and publishes "waiting for <port>: <holder>" as the
   daemon's current operation, which the CLI prints.
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "enabled" at "reviews.pre_merge_checks"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Fold the atomic self-eviction re-check into the existing condition.
Moves the load-average probe out of fbuild-cli into the platform facade
(getloadavg on Linux/macOS, None on Windows) so it stays behind the
platform boundary, and gives the liveness probe the medium HTTP timeout
so a daemon slowed by host load is not counted as unreachable.
@zackees
zackees added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit e21167a Nov 22, 2026
35 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 22, 2026
@zackees
zackees deleted the fix/load-tolerant-daemon-requests branch November 22, 2026 04:19
zackees added a commit that referenced this pull request Nov 22, 2026
…ain lacks

#2143 landed the core self-eviction fix on main (busy_reason counts the
drain counter, self-eviction commits with try_begin_shutdown), so this
branch's overlapping rewrite conflicted with it. Resolution keeps main's
busy_reason and adds what main still lacked:

- the eviction window predicate moves into entry/self_eviction.rs as
  try_self_evict(ctx, &mut empty_since, now, timeout), unit-tested with
  explicit instants instead of sleeping; mod.rs was at exactly the
  1000-LOC gate, so the predicate cannot stay inline;
- the 12-hour fallback now requires is_empty() and closes operation
  admission (try_begin_shutdown) before signalling shutdown, so the
  fallback cannot kill a daemon that is still building;
- a busy tick calls touch_activity(), so the fallback idle clock follows
  real work rather than wall time.

Verified: soldr cargo test -p fbuild-daemon --lib -> 339 passed, 0
failed, 3 ignored (includes the two self-eviction tests through the real
loop helper); soldr cargo clippy -p fbuild-daemon --lib --tests -D
warnings -> exit 0; cargo fmt --check clean; enforce_platform_boundary
rows=0 rc 0. mod.rs 995 LOC, self_eviction.rs 141 LOC.
sutaburosu pushed a commit to sutaburosu/FastLED that referenced this pull request Nov 22, 2026
… mid-build (FastLED#5410)

fbuild 2.5.52 cleared its shared operation-in-progress flag whenever any
operation finished, so with two concurrent builds the daemon self-evicted
30 s after the first one ended. The evicting daemon kept root-owner.lock while
draining, new clients timed out spawning replacements, and the eventual
SIGTERM killed in-flight builds and dropped device leases.
FastLED/fbuild#2143 (v2.5.53) counts active operations instead.

Verified locally: a 203 s build with an 11 s build finishing inside it kept
the 2.5.53 daemon alive until the long build completed.
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.

1 participant