Skip to content

Commit 5d9ad87

Browse files
authored
Merge pull request excon#676 from excon/retry-blocked-connect
also retry blocked connect with newer ruby error messages
2 parents 3bc977d + b08d525 commit 5d9ad87

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/excon/socket.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ class Socket
77

88
attr_accessor :data
99

10-
# drawn from https://github.com/ruby-amqp/bunny/commit/75d9dd79551b31a5dd3d1254c537bad471f108cf
11-
READ_RETRY_EXCEPTION_CLASSES = if defined?(IO::EAGAINWAITReadable) # Ruby >= 2.1
10+
# read/write drawn from https://github.com/ruby-amqp/bunny/commit/75d9dd79551b31a5dd3d1254c537bad471f108cf
11+
CONNECT_RETRY_EXCEPTION_CLASSES = if defined?(IO::EINPROGRESSWaitWritable) # Ruby >= 2.1
12+
[Errno::EINPROGRESS, IO::EINPROGRESSWaitWritable]
13+
else # Ruby <= 2.0
14+
[Errno::EINPROGRESS]
15+
end
16+
READ_RETRY_EXCEPTION_CLASSES = if defined?(IO::EAGAINWaitReadable) # Ruby >= 2.1
1217
[Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitReadable, IO::EAGAINWaitReadable, IO::EWOULDBLOCKWaitReadable]
1318
else # Ruby <= 2.0
1419
[Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitReadable]
@@ -118,7 +123,7 @@ def connect
118123
if @socket
119124
break
120125
end
121-
126+
122127
@remote_ip = ip
123128

124129
# nonblocking connect
@@ -140,7 +145,7 @@ def connect
140145
socket.connect(sockaddr)
141146
end
142147
@socket = socket
143-
rescue Errno::EINPROGRESS
148+
rescue *CONNECT_RETRY_EXCEPTION_CLASSES
144149
select_with_timeout(socket, :connect_write)
145150
begin
146151
socket.connect_nonblock(sockaddr)

0 commit comments

Comments
 (0)