diff --git a/lib/spring/application.rb b/lib/spring/application.rb index d713e82e..de0467c1 100644 --- a/lib/spring/application.rb +++ b/lib/spring/application.rb @@ -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 } diff --git a/lib/spring/client/run.rb b/lib/spring/client/run.rb index 51ce51e8..52ec20cf 100644 --- a/lib/spring/client/run.rb +++ b/lib/spring/client/run.rb @@ -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 diff --git a/test/support/acceptance_test.rb b/test/support/acceptance_test.rb index 79f9b71a..5d4b1237 100644 --- a/test/support/acceptance_test.rb +++ b/test/support/acceptance_test.rb @@ -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