Skip to content

Commit e66bc55

Browse files
rosaclaude
andcommitted
Keep shutting down when the plugin's output pipe is gone too
A closed terminal raises Errno::EIO, but the same monitor thread can also find its output gone as EPIPE (stdout piped to a reader that exited) or EBADF (stream already closed during shutdown). Treat the three the same way, and cover each in the test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CACej2M9mLVDwpE3Bk8V41
1 parent e8b7460 commit e66bc55

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

‎lib/puma/plugin/solid_queue.rb‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ def puma_dead?
139139

140140
def log(...)
141141
log_writer.log(...)
142-
rescue Errno::EIO
143-
# The controlling terminal can disappear before the monitor thread shuts
144-
# down the child process. Keep shutdown moving even when logging cannot.
142+
rescue Errno::EIO, Errno::EPIPE, Errno::EBADF
143+
# The controlling terminal can disappear, or the output pipe close, before
144+
# the monitor thread shuts down the child process. Keep shutdown moving
145+
# even when logging cannot.
145146
end
146147
end

‎test/unit/puma_plugin_test.rb‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@
44
require "puma/plugin/solid_queue"
55

66
class PumaPluginTest < ActiveSupport::TestCase
7-
class ClosedTerminalLogWriter
7+
class ClosedOutputLogWriter
8+
def initialize(error)
9+
@error = error
10+
end
11+
812
def log(...)
9-
raise Errno::EIO
13+
raise @error
1014
end
1115
end
1216

13-
test "monitor still stops the process when shutdown logging fails" do
14-
plugin = Puma::Plugins.find("solid_queue").new
15-
plugin.instance_variable_set(:@log_writer, ClosedTerminalLogWriter.new)
17+
[ Errno::EIO, Errno::EPIPE, Errno::EBADF ].each do |error|
18+
test "monitor still stops the process when shutdown logging fails with #{error}" do
19+
plugin = Puma::Plugins.find("solid_queue").new
20+
plugin.instance_variable_set(:@log_writer, ClosedOutputLogWriter.new(error))
1621

17-
plugin.stubs(:puma_dead?).returns(true)
18-
Process.expects(:kill).with(:INT, Process.pid)
22+
plugin.stubs(:puma_dead?).returns(true)
23+
Process.expects(:kill).with(:INT, Process.pid)
1924

20-
plugin.send(:monitor, :puma_dead?, "Detected Puma has gone away, stopping Solid Queue...")
25+
plugin.send(:monitor, :puma_dead?, "Detected Puma has gone away, stopping Solid Queue...")
26+
end
2127
end
2228
end

0 commit comments

Comments
 (0)