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

Prevent connections from entering Reactor after shutdown begins #2377

Merged
merged 1 commit into from Sep 23, 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
2 changes: 1 addition & 1 deletion History.md
Expand Up @@ -4,7 +4,7 @@
* Your feature goes here (#Github Number)

* Bugfixes
* Your bugfix goes here (#Github Number)
* Prevent connections from entering Reactor after shutdown begins (#2377)

## 5.0.0

Expand Down
31 changes: 19 additions & 12 deletions lib/puma/server.rb
Expand Up @@ -85,6 +85,8 @@ def initialize(app, events=Events.stdio, options={})
@precheck_closing = true

@requests_count = 0

@shutdown_mutex = Mutex.new
end

attr_accessor :binder, :leak_stack_on_error, :early_hints
Expand Down Expand Up @@ -237,12 +239,13 @@ def run(background=true)

@events.connection_error e, client
else
if process_now
process_client client, buffer
else
client.set_timeout @first_data_timeout
@reactor.add client
end
process_now ||= @shutdown_mutex.synchronize do
next true unless @queue_requests
client.set_timeout @first_data_timeout
@reactor.add client
false
end
process_client client, buffer if process_now
end

process_now
Expand Down Expand Up @@ -328,7 +331,9 @@ def handle_servers
@events.fire :state, @status

if queue_requests
@queue_requests = false
@shutdown_mutex.synchronize do
@queue_requests = false
end
@reactor.clear!
@reactor.shutdown
end
Expand Down Expand Up @@ -408,11 +413,13 @@ def process_client(client, buffer)
end

unless client.reset(check_for_more_data)
return unless @queue_requests
close_socket = false
client.set_timeout @persistent_timeout
@reactor.add client
return
@shutdown_mutex.synchronize do
return unless @queue_requests
close_socket = false
client.set_timeout @persistent_timeout
@reactor.add client
return
end
end
end
end
Expand Down