Skip to content

Commit d075f11

Browse files
authored
Merge pull request #744 from rails/pc-signal-exit-code
Pass signaled exit code properly to the client
2 parents bf8278a + ee08721 commit d075f11

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

lib/spring/application.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,10 @@ def wait(pid, streams, client)
378378
Spring.failsafe_thread {
379379
begin
380380
_, status = Process.wait2 pid
381-
log "#{pid} exited with #{status.exitstatus}"
381+
log "#{pid} exited with #{status.exitstatus || status.inspect}"
382382

383383
streams.each(&:close)
384-
client.puts(status.exitstatus)
384+
client.puts(status.exitstatus || status.to_i)
385385
client.close
386386
ensure
387387
@mutex.synchronize { @waiting.delete pid }

lib/spring/client/run.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,16 @@ def run_command(client, application)
184184
suspend_resume_on_tstp_cont(pid)
185185

186186
forward_signals(application)
187-
status = application.read.to_i
187+
status = application.read
188+
log "got exit status #{status.inspect}"
188189

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

191-
exit status
196+
exit status.to_i
192197
else
193198
log "got no pid"
194199
exit 1

test/support/acceptance_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,12 @@ class MyEngine < Rails::Engine
747747

748748
assert_failure app.spring_test_command, stderr: "omg (RuntimeError)"
749749
end
750+
751+
test "passes exit code from exit and signal" do
752+
artifacts = app.run("bin/rails runner 'Process.exit(7)'")
753+
code = artifacts[:status].exitstatus || artifacts[:status].termsig
754+
assert_equal 7, code, "Expected exit status to be 7, but was #{code}"
755+
end
750756
end
751757
end
752758
end

0 commit comments

Comments
 (0)