Skip to content

test: signal the reload child only after it has booted - #56

Merged
AdamMusa merged 1 commit into
mainfrom
fix/run-command-reload-flake
Nov 2, 2026
Merged

AdamMusa merged 1 commit into
mainfrom
fix/run-command-reload-flake

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Summary

packages/ruflet/test/run_command_test.rb#test_handle_reload_command_big_r_requests_full_restart was flaky under load: it failed 3 of 6 runs on unmodified main during engine test runs, and release verification kept hitting it. The failure is always line 373, assert status.signaled? ("R must terminate the child process group").

Root cause (test-only)

The test spawned ruby -e "sleep 30" and sent "R" (TERM to the process group) immediately. Process.spawn returns after exec, but the child Ruby is still booting at that point. It installs its signal handlers early and only then loads the gem prelude, RUBYOPT/-r files and so on.

  • If TERM lands before the handlers exist, the default action kills the child by signal, and the test passes.
  • If TERM lands after the handlers are installed but before user code runs, Ruby turns the SignalException into a plain exit 1. status.signaled? is then false, and the test fails.

Under load the parent is descheduled long enough for TERM to hit that window.

Reproduced deterministically by fault injection ($SP/team/qa-logs/dev-wave3/{slowboot,spawn_delay}.rb). The child's boot is made 0.5 s slower through RUBYOPT, and the test process sleeps 0.2 s after spawn, imitating being descheduled:

  • old test: 0/5 pass (fails at line 373, the same failure)
  • new test: 5/5 pass

The production code is correct. On "R", run_command.rb sets run_state[:restart] = true before signalling, and the run loop respawns whenever that flag is set, whatever the child's exit status. A child that exits 1 because R arrived mid-boot is still restarted. So only the test's assumption was wrong.

Fix

The test now synchronises on events, with no sleeps and no clocks:

  • The child forks a grandchild into its process group. Each writes one byte to a pipe once it is running user code, and the test blocks on reader.read(2) before sending "R".
  • After R: Process.wait2(child) must show the child died by a signal.
  • Both processes inherit the pipe's write end, so EOF on the read end proves the whole process group is gone. The old test only checked the direct child.
  • The IO.select(..., 60) and the children's sleep 120 only bound a broken R, so it fails instead of hanging. Nothing waits on them in the passing path.
  • ensure kills the group only if it wasn't already proven gone, so a reused PID is never targeted.

Mutation check: changing R to signal only the child PID (not the group) makes the new test fail with "the grandchild outlived R".

Proof

  • 30 consecutive passes at this head (799daaa) under load: an engine flutter test loop plus a ruflet_core per-file suite loop ran alongside, with load average 32–43 on 8 cores. The whole run_command_test.rb under the same load: 30 runs, 0 failures. Log: flake_proof2.log.
  • An earlier loaded run with load average 99–350: new 60/60, old 59/60 (flake_proof.log).
  • verify_pr.sh with RUBY_PKGS="ruflet_core ruflet ruflet_server": ruflet_core 145/145 files, ruflet 13/13, ruflet_server 11/11. PASS.

Engine: no change.

@AdamMusa
AdamMusa merged commit f68801f into main Nov 2, 2026
12 checks passed
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.

1 participant