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

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

* Add test for waiting with an open client connection

* Rescue IO::WaitReadable instead of EAGAIN for blocking read
On Windows, `read_nonblock` raises `Errno::EWOULDBLOCK` if a blocking read would occur, which is a different value from `Errno::EAGAIN`. Both of these errors are extended by `IO::WaitReadable` which is Ruby's recommended exception class for retrying `read_nonblock`.
This commit is contained in:
Will Jordan 2020-02-21 08:26:38 -08:00 committed by GitHub
parent a948c165ae
commit adb6170b77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View file

@ -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)

View file

@ -153,7 +153,7 @@ module Puma
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"
@ -349,7 +349,7 @@ module Puma
begin
chunk = @io.read_nonblock(want)
rescue Errno::EAGAIN
rescue IO::WaitReadable
return false
rescue SystemCallError, IOError
raise ConnectionError, "Connection error detected during read"

View file

@ -754,4 +754,17 @@ EOF
# 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