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

Rescue IO::WaitReadable instead of EAGAIN for blocking read #2121

Merged
merged 2 commits into from Feb 21, 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 @@ -13,6 +13,7 @@
* Windows update extconf.rb for use with ssp and varied Ruby/MSYS2 combinations (#2069)
* Preserve `BUNDLE_GEMFILE` env var when using `prune_bundler` (#1893)
* Send 408 request timeout even when queue requests is disabled (#2119)
* Rescue IO::WaitReadable instead of EAGAIN for blocking read (#2121)

* Refactor
* Remove unused loader argument from Plugin initializer (#2095)
Expand Down
4 changes: 2 additions & 2 deletions lib/puma/client.rb
Expand Up @@ -153,7 +153,7 @@ def try_to_finish

begin
data = @io.read_nonblock(CHUNK_SIZE)
rescue Errno::EAGAIN
rescue IO::WaitReadable
return false
rescue SystemCallError, IOError, EOFError
raise ConnectionError, "Connection error detected during read"
Expand Down Expand Up @@ -349,7 +349,7 @@ def read_body

begin
chunk = @io.read_nonblock(want)
rescue Errno::EAGAIN
rescue IO::WaitReadable
return false
rescue SystemCallError, IOError
raise ConnectionError, "Connection error detected during read"
Expand Down
13 changes: 13 additions & 0 deletions test/test_puma_server.rb
Expand Up @@ -754,4 +754,17 @@ def test_request_body_wait_chunked
# it is set to a reasonable number.
assert_operator request_body_wait, :>=, 900
end

def test_open_connection_wait
server_run app: ->(_) { [200, {}, ["Hello"]] }
s = send_http nil
sleep 0.1
s << "GET / HTTP/1.0\r\n\r\n"
assert_equal 'Hello', s.readlines.last
end

def test_open_connection_wait_no_queue
@server = Puma::Server.new @app, @events, queue_requests: false
test_open_connection_wait
end
end