Skip to content
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

Improve worker shutdown reliability, CI fixes #2312

Merged
merged 3 commits into from Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -33,6 +33,7 @@
* Log binding on http:// for TCP bindings to make it clickable

* Bugfixes
* Improve shutdown reliability (#2312)
* Close client http connections made to an ssl server with TLSv1.3 (#2116)
* Do not set user_config to quiet by default to allow for file config (#2074)
* Always close SSL connection in Puma::ControlCLI (#2211)
Expand Down
3 changes: 2 additions & 1 deletion lib/puma/events.rb
Expand Up @@ -65,7 +65,8 @@ def register(hook, obj=nil, &blk)
# Write +str+ to +@stdout+
#
def log(str)
@stdout.puts format(str)
@stdout.puts format(str) if @stdout.respond_to? :puts
rescue Errno::EPIPE
end

def write(str)
Expand Down
9 changes: 7 additions & 2 deletions lib/puma/server.rb
Expand Up @@ -317,7 +317,12 @@ def handle_servers
rescue Exception => e
@events.unknown_error e, nil, "Exception handling servers"
ensure
@check.close unless @check.closed? # Ruby 2.2 issue
begin
@check.close unless @check.closed?
rescue Errno::EBADF, RuntimeError
# RuntimeError is Ruby 2.2 issue, can't modify frozen IOError
# Errno::EBADF is infrequently raised
end
@notify.close
@notify = nil
@check = nil
Expand Down Expand Up @@ -912,7 +917,7 @@ def notify_safely(message)
@check, @notify = Puma::Util.pipe unless @notify
begin
@notify << message
rescue IOError
rescue IOError, NoMethodError, Errno::EPIPE
# The server, in another thread, is shutting down
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
rescue RuntimeError => e
Expand Down
7 changes: 5 additions & 2 deletions test/helper.rb
Expand Up @@ -58,8 +58,11 @@ module TimeoutEveryTestCase
class TestTookTooLong < Timeout::Error
end

def capture_exceptions(*)
::Timeout.timeout(RUBY_ENGINE == 'ruby' ? 60 : 120, TestTookTooLong) { super }
def time_it
t0 = Minitest.clock_time
::Timeout.timeout(RUBY_ENGINE == 'ruby' ? 60 : 120, TestTookTooLong) { yield }
ensure
self.time = Minitest.clock_time - t0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_integration_cluster.rb
Expand Up @@ -387,7 +387,7 @@ def bad_exit_pids(pids)
# used with thread_run to define correct 'refused' errors
def thread_run_refused(unix: false)
if unix
DARWIN ? [Errno::ENOENT, IOError] : [Errno::ENOENT]
[Errno::ENOENT, IOError]
else
DARWIN ? [Errno::ECONNREFUSED, Errno::EPIPE, EOFError] :
[Errno::ECONNREFUSED]
Expand Down