Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

- Fix an intermittent crash when restarting a command with `--exit` by
sharing the child's exit-status waiter between startup and shutdown.

## 0.15.0 (unreleased)

- Require Ruby 3.3 or newer.
Expand Down
7 changes: 7 additions & 0 deletions Fork.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Relaunch is a fork of [alexch/rerun](https://github.com/alexch/rerun).
Functional changes are listed newest first.

## September 13, 2026: Preserve exit status during restart

Fix [#1](https://github.com/spinels/relaunch/issues/1), an intermittent
`undefined method 'success?' for nil` crash when restarting with `--exit`.
Shutdown now waits for the existing detached process waiter instead of
collecting the child's status with a competing `Process.wait` call.

## September 13, 2026: Minimum Ruby version

Relaunch requires Ruby 3.3 or newer.
Expand Down
7 changes: 4 additions & 3 deletions lib/rerun/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def start
raise ExitException
end

status_thread = Process.detach(@pid) # so if the child exits, it dies
status_thread = @status_thread = Process.detach(@pid)

Signal.trap("INT") do # INT = control-C -- allows user to stop the top-level rerun process
die
Expand Down Expand Up @@ -250,6 +250,7 @@ def running?
# @returns true if the process dies
# @returns false if either sending the signal fails or the process fails to die
def signal_and_wait(signal)
status_thread = @status_thread

signal_sent = if windows?
force_kill = (signal == 'KILL')
Expand All @@ -262,9 +263,9 @@ def signal_and_wait(signal)
# the signal was successfully sent, so wait for the process to die
begin
timeout(@options[:wait]) do
Process.wait(@pid)
status_thread.join
end
process_status = $?
process_status = status_thread.value
say "Process ended: #{process_status}" if verbose?
true
rescue Timeout::Error
Expand Down
24 changes: 24 additions & 0 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ class Runner
end

describe "running" do
it "preserves the detached child's exit status when stopping in exit mode" do
options = Options::DEFAULTS.dup.merge(exit: true, background: true, notify: false)
runner = Runner.new("command", options)
status = instance_double(Process::Status, success?: false, exitstatus: nil)
waiter = instance_double(Thread)
watcher = instance_double(Watcher, start: nil, adapter: nil)

allow(runner).to receive(:run).and_return(12345)
allow(runner).to receive(:send_signal).and_return(true)
allow(runner).to receive(:notify)
allow(runner).to receive(:say)
allow(Signal).to receive(:trap)
allow(Watcher).to receive(:new).and_return(watcher)
allow(Process).to receive(:detach).with(12345).and_return(waiter)
allow(waiter).to receive(:join).and_return(waiter)
allow(waiter).to receive(:value) { status }
# A competing wait consumes the status before the detached waiter can.
allow(Process).to receive(:wait).with(12345) { status = nil }
allow(runner).to receive(:sleep) { runner.stop }

expect(runner).to receive(:notify).with("failed", "Exit status ")
expect { runner.start }.not_to raise_error
end

it "sends its child process a SIGINT when restarting"

it "dies when sent a control-C (SIGINT)"
Expand Down