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

Reactor refactor #2279

Merged
merged 3 commits into from Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -8,6 +8,7 @@

* Refactor
* Consolidate option handling in Server, Server small refactors, doc chang (#2389)
* Refactor Reactor and Client request buffering (#2279)

## 5.0.2 / 2020-09-28

Expand Down
27 changes: 13 additions & 14 deletions lib/puma/client.rb
Expand Up @@ -103,7 +103,12 @@ def in_data_phase
end

def set_timeout(val)
@timeout_at = Time.now + val
@timeout_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) + val
end

# Number of seconds until the timeout elapses.
def timeout
[@timeout_at - Process.clock_gettime(Process::CLOCK_MONOTONIC), 0].max
end

def reset(fast_check=true)
Expand Down Expand Up @@ -248,19 +253,13 @@ def eagerly_finish
end # IS_JRUBY

def finish(timeout)
return true if @ready
until try_to_finish
can_read = begin
IO.select([@to_io], nil, nil, timeout)
rescue ThreadPool::ForceShutdown
nil
end
unless can_read
write_error(408) if in_data_phase
raise ConnectionError
end
end
true
return if @ready
IO.select([@to_io], nil, nil, timeout) || timeout! until try_to_finish
end

def timeout!
write_error(408) if in_data_phase
raise ConnectionError
end

def write_error(status_code)
Expand Down
24 changes: 24 additions & 0 deletions lib/puma/queue_close.rb
@@ -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