Skip to content

fork-kit/heavy: the queue tests' own look waits for the lock in real time (#551) - #560

Merged
scuttletoby merged 1 commit into
mainfrom
fork/heavy-queue-test-lock-551
Nov 20, 2026
Merged

scuttletoby merged 1 commit into
mainfrom
fork/heavy-queue-test-lock-551

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

Fixes #551

Root cause

QueueTests.live() read the tickets through self.q, the test's queue on a fake clock. take() retries the lock every LOCK_RETRY (0.05 s) until lock_wait() (30 s) — but on the fake clock each pause() only advances the fake time, so the whole 30 s wait goes by in about a millisecond of real time. The tests that race real caller processes (test_a_waiter_killed_with_9_frees_its_place, test_two_callers_at_the_same_instant) poll live() while the caller takes the lock every 0.2 s to look and write its ticket. Whenever the test's look landed while the caller held the lock for a few real milliseconds (more likely on a loaded CI runner), it raised LockBusy at once.

heavy_queue.py itself is fine: a SIGKILLed process never keeps the flock (the kernel drops it with the process), and heavy's own verbs and peaks wait on the real clock. No retry or longer sleep was added.

Fix

live() takes the lock through a queue on the real clock (same box and settings), so it waits for a real holder in real time. Everything else in the tests stays on the fake clock.

Tests

  • test_a_look_waits_in_real_time_for_a_process_holding_the_lock: forced interleaving. A real process takes the queue lock and lets go 0.3 s later, and the test's look must wait for it. On the old code it fails with the same LockBusy ... stayed taken traceback as in CI (I ran it). With the fix it passes.
  • test_a_lock_holder_killed_with_9_frees_the_lock_at_once: the state question for the lock (stopped half-way). A process killed with -9 while it holds the lock leaves it free at once: a non-blocking flock succeeds, the next look works, and a rerun is admitted on its first look.
  • Already covered by existing tests: runs again (test_a_rerun_starts_clean_and_keeps_order), empty state after a reboot (test_after_a_reboot_the_folders_are_made_again), old or garbled tickets.
  • python3 -I -B fork-kit/heavy/tests/queue.test.py: 70 tests OK. The four lock-racing tests passed 5 runs in a row.

General vs project

General: test-only change in the fork kit's heavy queue tests. Nothing project-specific; no project config is involved.

🤖 Generated with Claude Code

…time (#551)

The tests that race real caller processes read the live tickets through
the test's fake-clock queue. Its lock wait (30 s in 0.05 s steps) passes
on the fake clock without any real time going by, so whenever a caller
held the queue lock for a few real milliseconds (deciding, writing its
ticket) the test's look raised LockBusy at once. heavy_queue.py is fine:
a SIGKILLed process never keeps the flock, and heavy's own verbs wait on
the real clock.

live() now takes the lock through a queue on the real clock. Two new
tests: a real process that holds the lock for 0.3 s (fails on the old
code with the same LockBusy as in CI), and a lock holder killed with -9
leaves the lock free at once for the next look and a rerun.

Fixes #551

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby
scuttletoby merged commit c09ed55 into main Nov 20, 2026
27 checks passed
scuttletoby added a commit that referenced this pull request Nov 21, 2026
#569: the CI failure tested a merge onto a base from before #560. There, the
test's live() look ran on the fake clock, so its 30 s lock wait passed in no
real time. #560 already moved live() to the real clock. Reproduced: 3 of 50
runs failed on the old base with 8 CPU hogs, 0 of 50 on this branch. The lock
release after SIGKILL is the kernel's flock drop, and tests on main cover it.

#744:
- signal_in signals only through a pidfd; no fallback to kill(pid)
- docker-label notes go to ~/.local/state/heavy/labelled when the /run/user note
  cannot reach heavy; heavy passes the folders it reads as HEAVY_MARKS
- the refusal under a shell after leaving heavy's scope names the cause
- tests: done() waits for the guard; the install test leaves no note; every
  read and wait of a test process has a timeout, checked by an AST test
- README: cgroup.kill reaches sudo/setuid processes; who refuses to start;
  the --value exit code

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
scuttletoby added a commit that referenced this pull request Nov 21, 2026
…time (#551) (#560)

The tests that race real caller processes read the live tickets through
the test's fake-clock queue. Its lock wait (30 s in 0.05 s steps) passes
on the fake clock without any real time going by, so whenever a caller
held the queue lock for a few real milliseconds (deciding, writing its
ticket) the test's look raised LockBusy at once. heavy_queue.py is fine:
a SIGKILLed process never keeps the flock, and heavy's own verbs wait on
the real clock.

live() now takes the lock through a queue on the real clock. Two new
tests: a real process that holds the lock for 0.3 s (fails on the old
code with the same LockBusy as in CI), and a lock holder killed with -9
leaves the lock free at once for the next look and a rerun.

Fixes #551

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
scuttletoby added a commit that referenced this pull request Nov 21, 2026
#569: the CI failure tested a merge onto a base from before #560. There, the
test's live() look ran on the fake clock, so its 30 s lock wait passed in no
real time. #560 already moved live() to the real clock. Reproduced: 3 of 50
runs failed on the old base with 8 CPU hogs, 0 of 50 on this branch. The lock
release after SIGKILL is the kernel's flock drop, and tests on main cover it.

#744:
- signal_in signals only through a pidfd; no fallback to kill(pid)
- docker-label notes go to ~/.local/state/heavy/labelled when the /run/user note
  cannot reach heavy; heavy passes the folders it reads as HEAVY_MARKS
- the refusal under a shell after leaving heavy's scope names the cause
- tests: done() waits for the guard; the install test leaves no note; every
  read and wait of a test process has a timeout, checked by an AST test
- README: cgroup.kill reaches sudo/setuid processes; who refuses to start;
  the --value exit code

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
scuttletoby added a commit that referenced this pull request Nov 21, 2026
…time (#551) (#560)

The tests that race real caller processes read the live tickets through
the test's fake-clock queue. Its lock wait (30 s in 0.05 s steps) passes
on the fake clock without any real time going by, so whenever a caller
held the queue lock for a few real milliseconds (deciding, writing its
ticket) the test's look raised LockBusy at once. heavy_queue.py is fine:
a SIGKILLed process never keeps the flock, and heavy's own verbs wait on
the real clock.

live() now takes the lock through a queue on the real clock. Two new
tests: a real process that holds the lock for 0.3 s (fails on the old
code with the same LockBusy as in CI), and a lock holder killed with -9
leaves the lock free at once for the next look and a rerun.

Fixes #551

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
scuttletoby added a commit that referenced this pull request Nov 21, 2026
#569: the CI failure tested a merge onto a base from before #560. There, the
test's live() look ran on the fake clock, so its 30 s lock wait passed in no
real time. #560 already moved live() to the real clock. Reproduced: 3 of 50
runs failed on the old base with 8 CPU hogs, 0 of 50 on this branch. The lock
release after SIGKILL is the kernel's flock drop, and tests on main cover it.

#744:
- signal_in signals only through a pidfd; no fallback to kill(pid)
- docker-label notes go to ~/.local/state/heavy/labelled when the /run/user note
  cannot reach heavy; heavy passes the folders it reads as HEAVY_MARKS
- the refusal under a shell after leaving heavy's scope names the cause
- tests: done() waits for the guard; the install test leaves no note; every
  read and wait of a test process has a timeout, checked by an AST test
- README: cgroup.kill reaches sudo/setuid processes; who refuses to start;
  the --value exit code

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
scuttletoby added a commit that referenced this pull request Nov 21, 2026
#569: the CI failure tested a merge onto a base from before #560. There, the
test's live() look ran on the fake clock, so its 30 s lock wait passed in no
real time. #560 already moved live() to the real clock. Reproduced: 3 of 50
runs failed on the old base with 8 CPU hogs, 0 of 50 on this branch. The lock
release after SIGKILL is the kernel's flock drop, and tests on main cover it.

#744:
- signal_in signals only through a pidfd; no fallback to kill(pid)
- docker-label notes go to ~/.local/state/heavy/labelled when the /run/user note
  cannot reach heavy; heavy passes the folders it reads as HEAVY_MARKS
- the refusal under a shell after leaving heavy's scope names the cause
- tests: done() waits for the guard; the install test leaves no note; every
  read and wait of a test process has a timeout, checked by an AST test
- README: cgroup.kill reaches sudo/setuid processes; who refuses to start;
  the --value exit code

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

fork-kit heavy: queue test 'a waiter killed with 9 frees its place' hit LockBusy in CI

1 participant