Repository navigation
fix: queue a hot reload requested while the app is still booting - #57
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Pressing "r" (hot reload) in
ruflet runwhile the app is still booting kills the app and ends the whole session.USR1to the app child immediately.USR1only inRuflet::HotReload::Runner#run, afterbundler/setup,ruflet_coreand the app script have loaded.USR1meets Ruby's default action, and the app dies bySIGUSR1. Withrestartfalse, the run loop then returns the child's status, and the session ends.Reproduced on unmodified
mainwith the real harness and an app held mid-boot on a FIFO ($SP/team/qa-logs/dev-wave3/old_reload_boot_repro.rb):Fix (option 1: the CLI queues the reload until the app reports ready)
This matches the CLI's design: the CLI owns the dev loop, and the child is the CLI's own harness. Option 2 (trap earlier in the child) cannot close the window, because Ruby's own boot and
-rbundler/setuprun before any harness code.Ruflet::HotReload::Runner#signal_ready(hot_reload.rb): right afterinstall_manual_reload_trap, the runner writes one byte to the fd named byRUFLET_READY_FD, closes it, and removes the variable. If the variable is absent it does nothing, so other launchers and the existing behaviour are unchanged.run_command.rb): when manual reload is active (reload on, a TTY, andUSR1exists), each app child is spawned throughspawn_app_child. This creates a pipe mapped to fd 3 in the child, and a small thread waits for the ready byte. "r" before ready is queued, and the CLI prints "Reload queued: the app is still starting and will reload once it is up". On the ready byte, a queued reload is delivered asUSR1. A mutex covers the check-and-queue and the ready-and-deliver steps, so no request is lost. A respawn ("R") resets readiness and drops a queued reload, because the fresh process loads the current code anyway. Without manual reload (including Windows, which has noUSR1) nothing changes.Tests
run_command_test.rb#test_reload_pressed_during_boot_is_applied_once_the_app_is_up: an end-to-end test with the real harness and the CLI's spawn helper. The app script holds its boot on a FIFO gate that the test owns, so "r" always lands mid-boot. Synchronisation is pipe/FIFO-readiness only, with no sleeps: the test waits forL1, presses "r" (asserting it is queued), opens the gate, then expectsL2, which is the queued reload actually running, and the app still alive.hot_reload_test.rb: the runner reports ready on the given fd once the watcher and trap are armed, closes the fd, and clears the variable. Without the variable it does nothing. The first test failed against the oldhot_reload.rb.Proof
flutter testloop and theruflet_coresuite loop ran alongside (load average up to 151). Log:reload_boot_proof.log.hot_reload_test.rbunder the same load: 12 runs, 0 failures.verify_pr.shwithRUBY_PKGS="ruflet_core ruflet ruflet_server": ruflet_core 145/145 files, ruflet 13/13, ruflet_server 11/11. PASS.Note: one earlier verify run on this branch failed only on
test_handle_reload_command_big_r_requests_full_restart, the known flake that #56 fixes; this branch is based onmain, which doesn't have it. With #56 merged in a scratch tree, the wholerun_command_test.rbpassed 15/15 under the same load. The two PRs merge cleanly.