Skip to content

Pass signaled exit code properly to the client #741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions lib/spring/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ def wait(pid, streams, client)
Spring.failsafe_thread {
begin
_, status = Process.wait2 pid
log "#{pid} exited with #{status.exitstatus}"
log "#{pid} exited with #{status.exitstatus || status.inspect}"

streams.each(&:close)
client.puts(status.exitstatus)
client.puts(status.exitstatus || status.to_i)
client.close
ensure
@mutex.synchronize { @waiting.delete pid }
Expand Down
11 changes: 8 additions & 3 deletions lib/spring/client/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,16 @@ def run_command(client, application)
suspend_resume_on_tstp_cont(pid)

forward_signals(application)
status = application.read.to_i
status = application.read
log "got exit status #{status.inspect}"

log "got exit status #{status}"
# Status should always be an integer. If it is empty, something unexpected must have happened to the server.
if status.to_s.strip.empty?
log "unexpected empty exit status, app crashed?"
exit 1
end

exit status
exit status.to_i
else
log "got no pid"
exit 1
Expand Down
10 changes: 10 additions & 0 deletions test/support/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,16 @@ class MyEngine < Rails::Engine

assert_failure app.spring_test_command, stderr: "omg (RuntimeError)"
end

test "passes exit code from exit and signal" do
artifacts = app.run("bin/rails runner 'Process.exit(7)'")
code = artifacts[:status].exitstatus || artifacts[:status].termsig
assert_equal 7, code, "Expected exit status to be 7, but was #{code}"

artifacts = app.run("bin/rails runner 'system(\"kill -7 \#{Process.pid}\")'")
code = artifacts[:status].exitstatus || artifacts[:status].termsig
assert_equal 7, code % 128, "Expected exit status to be 7, but was #{code}"
end
end
end
end
Loading