Skip to content

Commit

Permalink
Continuously retry on retriable exceptions
Browse files Browse the repository at this point in the history
This is a reasoanble thing for users to expect and IO.select docs
even have an example that do this for IO::WaitReadable.

Closes ruby-amqp#548.
  • Loading branch information
michaelklishin committed Apr 5, 2018
1 parent 193b0a2 commit 8572578
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
7 changes: 2 additions & 5 deletions lib/bunny/cruby/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ def read_fully(count, timeout = nil)
# @eof will break Rubinius' TCPSocket implementation. MK.
@__bunny_socket_eof_flag__ = true
rescue *READ_RETRY_EXCEPTION_CLASSES
if IO.select([self], nil, nil, timeout)
retry
else
raise Timeout::Error, "IO timeout when reading #{count} bytes"
end
IO.select([self], nil, nil, timeout)
retry
end
value
end # read_fully
Expand Down
14 changes: 4 additions & 10 deletions lib/bunny/cruby/ssl_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,14 @@ def read_fully(count, timeout = nil)
@__bunny_socket_eof_flag__ = true
rescue OpenSSL::SSL::SSLError => e
if e.message == "read would block"
if IO.select([self], nil, nil, timeout)
retry
else
raise Timeout::Error, "IO timeout when reading #{count} bytes"
end
IO.select([self], nil, nil, timeout)
retry
else
raise e
end
rescue *READ_RETRY_EXCEPTION_CLASSES => e
if IO.select([self], nil, nil, timeout)
retry
else
raise Timeout::Error, "IO timeout when reading #{count} bytes"
end
IO.select([self], nil, nil, timeout)
retry
end
value
end
Expand Down

0 comments on commit 8572578

Please sign in to comment.