From e734f625b1e996de7b3952ae6c92355793351de6 Mon Sep 17 00:00:00 2001 From: Andrii Furmanets Date: Wed, 29 Apr 2026 16:24:03 +0300 Subject: [PATCH] Ignore closed terminal log errors in Puma plugin --- lib/puma/plugin/solid_queue.rb | 3 +++ test/unit/puma_plugin_test.rb | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/unit/puma_plugin_test.rb diff --git a/lib/puma/plugin/solid_queue.rb b/lib/puma/plugin/solid_queue.rb index 8a7aea28..2285fd14 100644 --- a/lib/puma/plugin/solid_queue.rb +++ b/lib/puma/plugin/solid_queue.rb @@ -129,5 +129,8 @@ def puma_dead? def log(...) log_writer.log(...) + rescue Errno::EIO + # The controlling terminal can disappear before the monitor thread shuts + # down the child process. Keep shutdown moving even when logging cannot. end end diff --git a/test/unit/puma_plugin_test.rb b/test/unit/puma_plugin_test.rb new file mode 100644 index 00000000..710b01b4 --- /dev/null +++ b/test/unit/puma_plugin_test.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require "test_helper" +require "puma/plugin/solid_queue" + +class PumaPluginTest < ActiveSupport::TestCase + class ClosedTerminalLogWriter + def log(...) + raise Errno::EIO + end + end + + test "monitor still stops the process when shutdown logging fails" do + plugin = Puma::Plugins.find("solid_queue").new + plugin.instance_variable_set(:@log_writer, ClosedTerminalLogWriter.new) + + plugin.stubs(:puma_dead?).returns(true) + Process.expects(:kill).with(:INT, Process.pid) + + plugin.send(:monitor, :puma_dead?, "Detected Puma has gone away, stopping Solid Queue...") + end +end