Skip to content

Commit

Permalink
Avoid blocking on #read_nonblock
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus committed Jul 19, 2019
1 parent 099a447 commit 242e955
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/puma/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def read_chunked_body
while true
begin
chunk = @io.read_nonblock(4096)
rescue IO::WaitReadable
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
return false
rescue SystemCallError, IOError
raise ConnectionError, "Connection error detected during read"
Expand Down
24 changes: 8 additions & 16 deletions lib/puma/minissl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,14 @@ def read_nonblock(size, *_)
output = engine_read_all
return output if output

begin
data = @socket.read_nonblock(size, exception: false)
if data == :wait_readable || data == :wait_writable
if @socket.to_io.respond_to?(data)
@socket.to_io.__send__(data)
elsif data == :wait_readable
IO.select([@socket.to_io])
else
IO.select(nil, [@socket.to_io])
end
elsif !data
return nil
else
break
end
end while true
data = @socket.read_nonblock(size, exception: false)
if data == :wait_readable || data == :wait_writable
raise Errno::EAGAIN
elsif data.nil?
return nil
end

return nil if data.nil?

@engine.inject(data)
output = engine_read_all
Expand Down

0 comments on commit 242e955

Please sign in to comment.