Skip to content

Commit f0881e3

Browse files
titusfortnerandreastt
authored andcommitted
rb: retry ports unavailable by EADDRNOTAVAIL
This situation might occur when we exhaust the temporary port range on a machine with many TCP connections. It takes some time for the temporary sockets to be returned to the reusable pool, and in that short timespan there may be race conditions. Signed-off-by: Andreas Tolfsen <[email protected]>
1 parent c23dbbc commit f0881e3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Diff for: rb/lib/selenium/webdriver/remote/http/default.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ def http
3232
MAX_RETRIES = 3
3333

3434
def request(verb, url, headers, payload, redirects = 0)
35-
request = new_request_for(verb, url, headers, payload)
36-
3735
retries = 0
36+
3837
begin
38+
request = new_request_for(verb, url, headers, payload)
3939
response = response_for(request)
4040
rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EADDRINUSE
4141
# a retry is sometimes needed on Windows XP where we may quickly
@@ -46,11 +46,16 @@ def request(verb, url, headers, payload, redirects = 0)
4646
#
4747
# http://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx
4848
raise if retries >= MAX_RETRIES
49-
50-
request = new_request_for(verb, url, headers, payload)
5149
retries += 1
5250

5351
retry
52+
rescue Errno::EADDRNOTAVAIL => ex
53+
# a retry is sometimes needed when the port becomes temporarily unavailable
54+
raise if retries >= MAX_RETRIES
55+
retries += 1
56+
sleep 2
57+
retry
58+
5459
rescue Errno::ECONNREFUSED => ex
5560
if use_proxy?
5661
raise ex.class, "using proxy: #{proxy.http}"

0 commit comments

Comments
 (0)