Skip to content

fix(test): deadman watchdog + steal wedged build locks (#2430) - #2432

Merged
zackees merged 1 commit into
masterfrom
fix-test-watchdog-stale-lock-2430
May 9, 2026
Merged

zackees merged 1 commit into
masterfrom
fix-test-watchdog-stale-lock-2430

Conversation

@zackees

@zackees zackees commented May 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #2430. bash test --cpp could leave a hung Python process holding the libfastled_build SQLite lock past the 600s watchdog, blocking every subsequent test invocation for 120s.

Changes

  1. Deadman watchdog (test.py): a second daemon fires at _TIMEOUT_EVERYTHING + 60s and unconditionally calls os._exit(3) — the primary watchdog can wedge inside dump_thread_stacks()/psutil queries; the deadman bypasses all diagnostics so the process always dies on time.
  2. Lock cleanup before force-exit: both watchdog tiers release any libfastled_build locks held by this PID before exiting.
  3. Steal wedged-but-alive locks (build_lock.py): _check_stale_lock now also breaks locks whose holder has held past FASTLED_LOCK_MAX_HOLD_S (default 3600s — well above the longest legitimate hold including 2700s sequential debug-sanitizer builds).
  4. Kill hint in lock-timeout error: platform-aware taskkill /F /PID N (Windows) or kill -9 N (Unix), plus a pointer to lock_admin --clean-stale.
  5. Line-buffered stdout/stderr when piped: defends against the silent bash test --cpp 2>&1 | tail -15 zero-byte symptom — when stdout is not a TTY, force line buffering so each \n-terminated line surfaces immediately.

Test plan

  • uv run pytest ci/tests/test_build_lock_wedged_steal.py — 2 new tests pass (positive + negative wedged-steal cases)
  • uv run pytest ci/tests/test_stale_lock_recovery.py ci/tests/test_lock_database.py ci/tests/test_cache_lock.py — 32 existing lock tests pass (no regressions)
  • bash lint — clean
  • bash test --list-tests — startup smoke test OK
  • CI verifies the watchdog/lock changes don't regress full-run behavior

Notes on design

  • I left _TIMEOUT_EVERYTHING = 600 and the timeout-bumping logic untouched. The deadman is purely additive insurance.
  • The wedged-lock-steal threshold is intentionally generous (3600s) to avoid false positives. The intent is "this can't possibly be legitimate; the holder's watchdog should have fired by now." A wedged process that survives past this threshold is the bug — the steal is the safety net.
  • I did not attempt to disable rich/ANSI progress when piped (low-priority item in the issue) — line-buffering is the smaller, safer defensive measure.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved build lock handling to detect and break long-held ("wedged") processes
    • Enhanced timeout error messages with process information and recovery guidance
    • Strengthened watchdog timeout cleanup mechanisms
    • Added configurable max lock hold duration threshold
  • Tests

    • Added tests for wedged lock detection and cleanup behavior

Review Change Stack

)

Fixes #2430. `bash test --cpp` could leave a hung Python process holding
the libfastled_build SQLite lock past the 600s watchdog timeout, blocking
every subsequent test invocation for 120s before timing out.

Changes:

1. **Deadman watchdog** in test.py — adds a second-tier daemon that fires
   `_TIMEOUT_EVERYTHING + 60s` and unconditionally calls `os._exit(3)`.
   The primary watchdog can wedge in `dump_thread_stacks()` or psutil
   queries; the deadman bypasses all diagnostics so the process always
   dies on time.

2. **Lock cleanup before force-exit** — both the primary watchdog and the
   deadman now release any libfastled_build locks held by this PID
   before exiting, so subsequent runs are not blocked even if the
   diagnostics path stalls.

3. **Steal alive-but-wedged locks** in build_lock.py — `_check_stale_lock`
   now also breaks locks whose holder PID is alive but has held past
   `FASTLED_LOCK_MAX_HOLD_S` (default 3600s — well above the longest
   legitimate hold, including 2700s sequential debug-sanitizer builds).
   This is the safety net for the case where a process is wedged but
   neither watchdog tier fired.

4. **Kill hint in lock-timeout error** — the `Failed to acquire ...`
   error now includes a platform-aware `taskkill /F /PID N` (Windows) or
   `kill -9 N` (Unix) suggestion plus a pointer to `lock_admin
   --clean-stale`.

5. **Line-buffer stdout/stderr when piped** — defends against the silent
   `bash test --cpp 2>&1 | tail -15` zero-byte-output symptom by forcing
   line buffering when stdout is not a TTY, so each `\n`-terminated line
   surfaces immediately to the consuming pipe.

Tests: new `ci/tests/test_build_lock_wedged_steal.py` covers
the wedged-but-alive steal path (positive + negative case). All 32
existing lock tests still pass; `bash lint` clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented May 9, 2026 •

Copy link
Copy Markdown

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: 2bcd1c3f-79b8-44ec-9c9d-a8eb0a064aba

📥 Commits

Reviewing files that changed from the base of the PR and between 68106e8 and b9fc1da.

📒 Files selected for processing (3)
  • ci/tests/test_build_lock_wedged_steal.py
  • ci/util/build_lock.py
  • test.py

📝 Walkthrough

Walkthrough

This PR hardens the build-lock system against hung processes and improves test-runner observability. It introduces configurable wedged-lock detection (stealing locks held alive but past a max-hold threshold), a deadman-timer layer in the watchdog, explicit lock release before watchdog timeout, better piped-output visibility, and tests verifying the wedged-lock stealing behavior.

Changes

Build Lock Wedged-Hold Stealing & Watchdog Hardening

Layer / File(s) Summary
Lock Max-Hold Configuration
ci/util/build_lock.py
Introduces _DEFAULT_MAX_HOLD_S (3600 s, 60 min) configurable via FASTLED_LOCK_MAX_HOLD_S env var as the threshold for stealing alive-but-wedged locks.
Wedged-Lock Detection Logic
ci/util/build_lock.py
Adds _max_hold_seconds() method and reworks _check_stale_lock() to steal locks when all holders are dead or any holder exceeds max-hold age; improved diagnostics distinguish dead vs. wedged cases.
Timeout Error Enrichment
ci/util/build_lock.py
Timeout error messages now include per-holder process info (name, command), hold duration, and OS-specific kill hints (taskkill on Windows, kill -9 on POSIX), plus cleanup tips.
Output & Watchdog Integration
test.py
Line-buffers stdout/stderr when not a TTY; introduces deadman timer with grace period that releases locks before force-exit; primary watchdog also releases locks before timeout warning.
Wedged-Lock Tests
ci/tests/test_build_lock_wedged_steal.py
New TestBuildLockWedgedSteal class verifies _check_stale_lock() steals old-held locks (current PID, past threshold) and preserves recent locks; uses hermetic temp SQLite DB and overridden FASTLED_LOCK_MAX_HOLD_S.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes


🐰 A lock once hung round the neck of time,
Now stolen when its age runs past the line.
The watchdog's grace, a deadman's second swing,
Release and exit—let the next test ring!
No silent pipes, just progress on the screen.

✨ 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-test-watchdog-stale-lock-2430

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 and usage tips.

@zackees
zackees merged commit 8a339fc into master May 9, 2026
5 of 7 checks passed
@zackees
zackees deleted the fix-test-watchdog-stale-lock-2430 branch May 9, 2026 23:12
zackees added a commit that referenced this pull request May 10, 2026
…3a of #2428) (#2433)

Adds a non-template polymorphic anchor `fl::IChannel` so ChannelEvents callbacks
keep working after `Channel<Bus, Chipset>` becomes a template in Phase 3b.

Phase 3a is purely an API surface refactor -- no behavior changes:

- New: src/fl/channels/ichannel.h. Minimal ABC with virtual `id()` and `name()`,
  noexcept special members, non-copyable/movable. Holds the public surface that
  any callback might reasonably want.
- Channel now derives from CPixelLEDController<RGB> AND IChannel; existing
  `id()` / `name()` accessors marked `override`.
- ChannelEvents callbacks change from `function_list<void(const Channel&, ...)>`
  to `function_list<void(const IChannel&, ...)>`. Callsites that fire events
  pass `*this` which upcasts implicitly via the new inheritance.
- Test/doc lambdas migrated: tests/fastled_core.cpp EventTracker stores
  `const IChannel*`; lambdas in fastled_core.cpp, fl/channels/driver.cpp,
  fl/chipsets/ucs7604.cpp updated. README and FastLED.h docstrings refreshed.

Also fixes pre-existing KBI checker failures in test.py (lines 186/193/211)
flagged by lint -- the test-lock fix from #2432 introduced try-except blocks
catching Exception without KeyboardInterrupt re-raise. Added the standard
`except KeyboardInterrupt as ki: handle_keyboard_interrupt(ki); raise`
clause before each `except Exception`.

Verification:
- bash lint clean.
- bash test --cpp passes (286/286).
- ChannelEvents tests verified: pointer-identity comparisons
  `tracker.mLastChannel == channel.get()` still work because Channel inherits
  from IChannel (implicit upcast).

Stacked on top of Phase 2 (#2431). When Phase 3b lands, Channel<B, Chipset>
will simply derive from IChannel the same way -- no further event-system
changes needed.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request May 10, 2026
…3a of #2428)

Adds a non-template polymorphic anchor `fl::IChannel` so ChannelEvents callbacks
keep working after `Channel<Bus, Chipset>` becomes a template in Phase 3b.
Pure API surface refactor -- no behavior changes.

- New: src/fl/channels/ichannel.h. Minimal ABC with virtual `id()` and `name()`,
  noexcept special members, non-copyable/movable. Holds the public surface that
  any callback might reasonably want.
- Channel now derives from CPixelLEDController<RGB> AND IChannel; existing
  `id()` / `name()` accessors marked `override`.
- ChannelEvents callbacks change from `function_list<void(const Channel&, ...)>`
  to `function_list<void(const IChannel&, ...)>`. Callsites that fire events
  pass `*this` which upcasts implicitly via the new inheritance.
- Test/doc lambdas migrated: tests/fastled_core.cpp EventTracker stores
  `const IChannel*`; lambdas in fastled_core.cpp, fl/channels/driver.cpp,
  fl/chipsets/ucs7604.cpp updated. README and FastLED.h docstrings refreshed.

Also fixes pre-existing KBI checker failures in test.py (lines 186/193/211)
flagged by lint -- the test-lock fix from #2432 introduced try-except blocks
catching Exception without KeyboardInterrupt re-raise. Added the standard
`except KeyboardInterrupt as ki: handle_keyboard_interrupt(ki)` clause before
each `except Exception`. Per CodeRabbit feedback on PR #2435, the cleanup
intentionally suppresses (does NOT re-raise) KeyboardInterrupt because:
- _release_held_build_locks() is best-effort cleanup called by deadman_timer
  and watchdog_timer, both of which call os._exit() unconditionally afterward.
- Re-raising would short-circuit the os._exit() and defeat the watchdog.

Verification:
- bash lint clean.
- bash test --cpp passes (303/303).
- ChannelEvents tests verified: pointer-identity comparisons
  `tracker.mLastChannel == channel.get()` still work because Channel inherits
  from IChannel (implicit upcast).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request May 10, 2026
…3a of #2428)

Adds a non-template polymorphic anchor `fl::IChannel` so ChannelEvents callbacks
keep working after `Channel<Bus, Chipset>` becomes a template in Phase 3b.
Pure API surface refactor -- no behavior changes.

- New: src/fl/channels/ichannel.h. Minimal ABC with virtual `id()` and `name()`,
  noexcept special members, non-copyable/movable. Holds the public surface that
  any callback might reasonably want.
- Channel now derives from CPixelLEDController<RGB> AND IChannel; existing
  `id()` / `name()` accessors marked `override`.
- ChannelEvents callbacks change from `function_list<void(const Channel&, ...)>`
  to `function_list<void(const IChannel&, ...)>`. Callsites that fire events
  pass `*this` which upcasts implicitly via the new inheritance.
- Test/doc lambdas migrated: tests/fastled_core.cpp EventTracker stores
  `const IChannel*`; lambdas in fastled_core.cpp, fl/channels/driver.cpp,
  fl/chipsets/ucs7604.cpp updated. README and FastLED.h docstrings refreshed.

Also fixes pre-existing KBI checker failures in test.py (lines 186/193/211)
flagged by lint -- the test-lock fix from #2432 introduced try-except blocks
catching Exception without KeyboardInterrupt re-raise. Added the standard
`except KeyboardInterrupt as ki: handle_keyboard_interrupt(ki)` clause before
each `except Exception`. Per CodeRabbit feedback on PR #2435, the cleanup
intentionally suppresses (does NOT re-raise) KeyboardInterrupt because:
- _release_held_build_locks() is best-effort cleanup called by deadman_timer
  and watchdog_timer, both of which call os._exit() unconditionally afterward.
- Re-raising would short-circuit the os._exit() and defeat the watchdog.

Verification:
- bash lint clean.
- bash test --cpp passes (303/303).
- ChannelEvents tests verified: pointer-identity comparisons
  `tracker.mLastChannel == channel.get()` still work because Channel inherits
  from IChannel (implicit upcast).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request May 10, 2026
…3a of #2428) (#2435)

Adds a non-template polymorphic anchor `fl::IChannel` so ChannelEvents callbacks
keep working after `Channel<Bus, Chipset>` becomes a template in Phase 3b.
Pure API surface refactor -- no behavior changes.

- New: src/fl/channels/ichannel.h. Minimal ABC with virtual `id()` and `name()`,
  noexcept special members, non-copyable/movable. Holds the public surface that
  any callback might reasonably want.
- Channel now derives from CPixelLEDController<RGB> AND IChannel; existing
  `id()` / `name()` accessors marked `override`.
- ChannelEvents callbacks change from `function_list<void(const Channel&, ...)>`
  to `function_list<void(const IChannel&, ...)>`. Callsites that fire events
  pass `*this` which upcasts implicitly via the new inheritance.
- Test/doc lambdas migrated: tests/fastled_core.cpp EventTracker stores
  `const IChannel*`; lambdas in fastled_core.cpp, fl/channels/driver.cpp,
  fl/chipsets/ucs7604.cpp updated. README and FastLED.h docstrings refreshed.

Also fixes pre-existing KBI checker failures in test.py (lines 186/193/211)
flagged by lint -- the test-lock fix from #2432 introduced try-except blocks
catching Exception without KeyboardInterrupt re-raise. Added the standard
`except KeyboardInterrupt as ki: handle_keyboard_interrupt(ki)` clause before
each `except Exception`. Per CodeRabbit feedback on PR #2435, the cleanup
intentionally suppresses (does NOT re-raise) KeyboardInterrupt because:
- _release_held_build_locks() is best-effort cleanup called by deadman_timer
  and watchdog_timer, both of which call os._exit() unconditionally afterward.
- Re-raising would short-circuit the os._exit() and defeat the watchdog.

Verification:
- bash lint clean.
- bash test --cpp passes (303/303).
- ChannelEvents tests verified: pointer-identity comparisons
  `tracker.mLastChannel == channel.get()` still work because Channel inherits
  from IChannel (implicit upcast).

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci(test): bash test --cpp can hang silently and block future runs for 120s on stale build lock

1 participant