mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00

* 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>
24 lines
521 B
Ruby
24 lines
521 B
Ruby
# 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
|