Skip to content

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

Closed

Description

@zackees

Summary

bash test --cpp can leave a previous test process hung indefinitely while holding the libfastled_build SQLite lock, blocking every subsequent test invocation for 120 s before timing out with a "lock blocked" diagnostic. Two related observations:

  1. Lock-holder runs past the watchdog timeout. test.py declares _TIMEOUT_EVERYTHING = 600 (10 minutes), but in this session a test process (python.exe PID 26892) was observed holding the lock for 803 s (~13.5 min) and was still alive — the watchdog/force-exit either never fired or failed to release the lock.
  2. Backgrounded invocations can complete with zero captured output despite exit 0. Running bash test --cpp 2>&1 | tail -15 in the background produces a zero-byte output file even when the underlying build/test succeeded. Likely cause: tail -15 only sees \n-terminated lines, but the test runner emits ANSI progress bars using \r overwrites; when stdout is piped (not a TTY), the renderer may emit no \n-terminated content, so tail captures nothing.

The combination is painful: a backgrounded bash test --cpp appears to hang silently (no output), and once it eventually exits, subsequent foreground runs block for 120 s waiting for a stale lock that the watchdog should have cleared.

Reproduction

Tested on Windows 10, bash shell (Git for Windows), master HEAD ebb48e610f plus a Phase 2 channels refactor branch with ~25 modified/added files (mostly per-platform bus_traits.h headers and edits to driver _build.cpp.hpp unity-build aggregators).

# 1) Clean tree, on a feature branch with ~25 pending changes.
git status

# 2) First test run completes normally (~25-90 s for incremental, full).
bash test --cpp     # passes 303/303 or 221/221 depending on fingerprint cache state

# 3) Second test run, this time backgrounded by a tool harness with the same
#    pipe-to-tail pattern that long-running task wrappers use.
#    Reproduce with the equivalent shell command:
bash test --cpp 2>&1 | tail -15 > /tmp/output.log &
BGPID=$!
wait $BGPID
echo "exit=$?"
wc -c /tmp/output.log

# Observed: exit=0, /tmp/output.log size=0 bytes. The build/test "succeeded"
# but no captured stdout, so no way to tell whether 0/0 or 303/303 ran.

# 4) Subsequent foreground run blocks for 120 s, then dumps stacks:
bash test --cpp
# After ~120 s:
#   [MESON] Failed to acquire libfastled build lock after 120s.
#     Held by: PID <N> (held 600s+, name=python.exe, exe=...python.exe,
#                       cmd=...test.py --cpp)
#   [LOCK] Blocked on 'build:libfastled_build' for 2s - dumping stacks:

# 5) Manual recovery (Windows):
taskkill //PID <N> //F

In this session the held duration of the stuck process was 803 s, well past _TIMEOUT_EVERYTHING = 600 set in test.py:79.

Files / code paths likely involved

  • test.py:79 — _TIMEOUT_EVERYTHING = 600 (10 min watchdog).
  • test.py:77 — _CANCEL_WATCHDOG = threading.Event() (cancellation signal).
  • ci/util/build_lock.py:28 — LOCK_TIMEOUT_S = 120.0 lock-acquisition timeout.
  • ci/util/build_lock.py:35-69 — process-alive checks via psutil.
  • ci/util/test_env.py — dump_thread_stacks, setup_force_exit watchdog wiring.
  • The bash test wrapper is just uv run test.py "$@".

Suggested fixes (in priority order)

High — make the watchdog actually kill the process

_TIMEOUT_EVERYTHING = 600 should be a hard wall. If the test main thread is past 600 s, the watchdog should:

  1. Dump thread stacks once.
  2. Release any held SQLite locks via the existing build_lock cleanup hooks.
  3. os._exit(<nonzero>) to bypass any blocked atexit handlers / hung join().

The current setup (_TIMEOUT_EVERYTHING + setup_force_exit in test_env.py) is not reliably terminating runaway test processes. Consider:

  • Sending signal.SIGABRT from a daemon thread before falling back to os._exit().
  • Verifying the watchdog thread itself is daemonized so it can't be silently joined out by the main thread's exit machinery.
  • A second-tier "deadman" timer at _TIMEOUT_EVERYTHING + 60s that does os._exit() unconditionally.

High — release libfastled_build lock when the holder dies

The build_lock already has PID-based stale-lock detection (_is_process_alive_psutil), but waited 120 s before checking and emitting diagnostics for a process that was alive but hung. Add:

  • An "alive but unresponsive" detection: if the holder PID has been holding the lock past _TIMEOUT_EVERYTHING + 30s, treat the lock as stale and steal it (with a loud warning).
  • Or: have the holder's watchdog explicitly release the lock before force-exit.

Medium — fix the silent-pipe issue

When stdout is not a TTY, the test runner should suppress ANSI progress bars (or replace \r-overwrites with newline-terminated periodic status lines) so that bash test --cpp 2>&1 | tail -15 captures something useful — even just the final summary.

isatty() check on stdout at startup, switching the renderer to plain-line mode when piped, would be the standard fix.

Low — surface a clear error from the lock-blocking path

The current error is good (Held by: PID 26892 (held 803s, name=python.exe, ...)) but doesn't suggest a remedy. Add a one-line hint:

Tip: if the holder appears stuck, run:  taskkill /PID 26892 /F   (Windows)
                                        kill -9 26892             (Linux/macOS)

Impact

  • Developer flow: silent hangs in agent-driven CI workflows that wrap test runs in a 10-minute timeout (the test exits silently with empty captured output, the agent moves on, the next test hangs 120 s on the stale lock).
  • CI: a single hung test can block all subsequent test invocations on the same machine for the lifetime of the lock holder.
  • Debuggability: no captured stdout from the hung process means there's no way to tell what the test was doing when it hung.

Environment

Activity

  1. added
    type: bug
    priority: high
    area: ci
    on May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cipriority: hightype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions