Skip to content

Commit

Permalink
rb: retry ports unavailable by EADDRNOTAVAIL
Browse files Browse the repository at this point in the history
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 <ato@mozilla.com>
  • Loading branch information
titusfortner authored and andreastt committed Apr 3, 2015
1 parent c23dbbc commit f0881e3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions rb/lib/selenium/webdriver/remote/http/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def http
MAX_RETRIES = 3

def request(verb, url, headers, payload, redirects = 0)
request = new_request_for(verb, url, headers, payload)

retries = 0

begin
request = new_request_for(verb, url, headers, payload)
response = response_for(request)
rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EADDRINUSE
# a retry is sometimes needed on Windows XP where we may quickly
Expand All @@ -46,11 +46,16 @@ def request(verb, url, headers, payload, redirects = 0)
#
# http://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx
raise if retries >= MAX_RETRIES

request = new_request_for(verb, url, headers, payload)
retries += 1

retry
rescue Errno::EADDRNOTAVAIL => ex
# a retry is sometimes needed when the port becomes temporarily unavailable
raise if retries >= MAX_RETRIES
retries += 1
sleep 2
retry

rescue Errno::ECONNREFUSED => ex
if use_proxy?
raise ex.class, "using proxy: #{proxy.http}"
Expand Down

0 comments on commit f0881e3

Please sign in to comment.