Skip to content

Commit

Permalink
[activexml] do not retry failed connections
Browse files Browse the repository at this point in the history
This was needed back in lighttd days
  • Loading branch information
coolo committed Sep 17, 2013
1 parent 20740ef commit f99a23e
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/activexml/transport.rb
Expand Up @@ -293,7 +293,6 @@ def http_do( method, url, opt={} )
@mutex.lock
defaults = {:timeout => 60}
opt = defaults.merge opt
max_retries = 1

if url.kind_of? String
url = URI(url)
Expand All @@ -314,12 +313,9 @@ def http_do( method, url, opt={} )
keepalive = false
when :get
# if the http existed before, we shall retry
max_retries = 2 if @http
keepalive = true
end
retries = 0
begin
retries += 1
if not @http
@http = Net::HTTP.new(url.host, url.port)
@http.use_ssl = true if url.scheme == "https"
Expand All @@ -332,7 +328,7 @@ def http_do( method, url, opt={} )
raise "url.path.nil" if url.path.nil?
path = url.path
path += "?" + url.query if url.query
logger.debug "http_do ##{retries}: method: #{method} url: " +
logger.debug "http_do: method: #{method} url: " +
"http#{"s" if @http.use_ssl?}://#{url.host}:#{url.port}#{path}"

clength = { "Content-Length" => "0" }
Expand Down Expand Up @@ -363,16 +359,12 @@ def http_do( method, url, opt={} )
else
raise "unknown HTTP method: #{method.inspect}"
end
rescue Timeout::Error, Errno::ETIMEDOUT
rescue Timeout::Error, Errno::ETIMEDOUT, EOFError
logger.error "--> caught timeout, closing HTTP"
keepalive = false
raise Timeout::Error
rescue SocketError, Errno::EINTR, Errno::EPIPE, EOFError, Net::HTTPBadResponse, IOError => err
rescue SocketError, Errno::EINTR, Errno::EPIPE, Net::HTTPBadResponse, IOError => err
keepalive = false
if retries < max_retries
logger.error "--> caught #{err.class}: #{err.message}, retrying with new HTTP connection"
retry
end
raise ConnectionError, "Connection failed #{err.class}: #{err.message} for #{url}"
rescue SystemCallError => err
keepalive = false
Expand Down

0 comments on commit f99a23e

Please sign in to comment.