Give the Puma plugin the pid of the litestream process - #77
Open
cole-robertson wants to merge 1 commit into
Open
Give the Puma plugin the pid of the litestream process#77cole-robertson wants to merge 1 commit into
cole-robertson wants to merge 1 commit into
Conversation
Since 0.14 the plugin forked a Ruby child that called Commands.replicate(async: true), which forked again and exec'd the binary. The plugin held the outer pid, which exited as a zombie while the daemon was reparented to init. On Puma stop the hook fired, sent INT to the dead pid, and replication kept running. Commands.replicate(async: true) now uses Process.spawn and returns the daemon's pid; the plugin holds that pid and its INT-then-wait works. The extra monitor_puma thread went with the Ruby child; it could only run inside a Ruby process, and it only covered the case where Puma died without running its stop hooks.
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.
Standalone fix for a bug that exists on the current 0.14.0 release. Independent of the 0.5 work.
Problem
Since 0.14 (#62) the Puma plugin forks a Ruby child that calls
Commands.replicate(async: true), which forks again and execs the binary. The plugin holds the outer pid, which exits immediately as a zombie, while the daemon is reparented to init. On Puma stop the hook fires, sends INT to the dead pid, and replication keeps running.Reproduced on upstream main in a fresh Rails 8 app with Puma 8.0.2: after boot the tree under Puma was
[ruby] <defunct>and the daemon's parent was init; afterkill -INTon Puma the log saidStopping Litestream...and the daemon was still running. Three runs, same result.Change
Commands.replicate(async: true)usesProcess.spawnand returns the daemon's own pid. The plugin holds that pid, so its existing INT-then-wait works. Themonitor_pumathread goes with the Ruby child: it could only run inside a Ruby process, and it only covered Puma dying without running its stop hooks.Verified
kill -INTthe daemon logssignal received, litestream shutting downbefore Puma'sGoodbye!, and nolitestream replicateprocess survives.Puma 8 deprecates the
on_booted/on_stopped/on_restarthook names in favour ofafter_booted/after_stopped/before_restart; they still fire, so that is left alone here.