Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor Reactor and Client request buffering Refactor Reactor into a more generic IO-with-timeout monitor, using a Queue to simplify the implementation. Move request-buffering logic into Server#reactor_wakeup. Fixes bug in managing timeouts on clients. Move, update and rewrite documentation to match updated class structure. * Fix a few concurrency bugs - In `Reactor#shutdown`, `@selector` can be closed before the call to `#wakeup`, so catch/ignore the `IOError` that may be thrown. - `Reactor#wakeup!` can delete elements from the `@timeouts` array so calling it from an `#each` block can cause the array iteration to miss elements. Call @block directly instead. - Change `Reactor#add` to return `false` if the reactor is already shut down instead of invoking the block immediately, so a client-request currently being processed can continue, rather than re-adding to the thread-pool (which may already be shutting down and unable to accept new work). Co-authored-by: Nate Berkopec <nate.berkopec@gmail.com>
- Loading branch information
1 parent
8f9396f
commit a76d390
Showing
5 changed files
with
221 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Queue#close was added in Ruby 2.3. | ||
# Add a simple implementation for earlier Ruby versions. | ||
unless Queue.instance_methods.include?(:close) | ||
class ClosedQueueError < StandardError; end | ||
module Puma | ||
module QueueClose | ||
def initialize | ||
@closed = false | ||
super | ||
end | ||
def close | ||
@closed = true | ||
end | ||
def closed? | ||
@closed | ||
end | ||
def push(object) | ||
raise ClosedQueueError if @closed | ||
super | ||
end | ||
end | ||
Queue.prepend QueueClose | ||
end | ||
end |
Oops, something went wrong.