Skip to content

2nd request unable to redefine read_timeout after 1st request #33

Closed
mislav opened this Issue Aug 12, 2012 · 2 comments

2 participants

@mislav
mislav commented Aug 12, 2012

I'm making 2 requests to the same local server, each instantiating a new Persistent object.

  • 1st request is done without a read_timeout,
  • while the 2nd request has a read_timeout of 1s and hits a resource that sleeps for 10s.
  • The 2nd request should time out after 1s, but does not because it remembers the read_timeout setting from the 1st request.
  • If I comment out the 1st request, the 2nd now has proper timeout of 1s.
require 'net/http/persistent'
require 'uri'

def req uri, timeout = false
  uri = URI(uri.to_s)
  http = Net::HTTP::Persistent.new 'Faraday'
  request = Net::HTTPGenericRequest.new 'GET', false, true, uri.request_uri
  http.read_timeout = timeout if timeout != false
  http.request uri, request
end

# 1st GET request with no timeout
req('http://127.0.0.1:4567/echo', nil)

begin
  # "/slow" is a resource that sleeps for 10 seconds
  p req('http://127.0.0.1:4567/slow', 1)
  abort "this shouldn't happen!"
rescue Net::HTTP::Persistent::Error
  puts $!.message
  puts "Good."
end
@drbrain
Owner
drbrain commented Oct 18, 2012

Currently read_timeout is only set when the connection is started. I'll rearrange some things to make it settable per-request.

@drbrain drbrain closed this in 2dd5f8b Oct 18, 2012
@drbrain
Owner
drbrain commented Oct 18, 2012

Oops, that should say "request"

@mislav mislav added a commit to lostisland/faraday that referenced this issue Apr 3, 2013
@mislav mislav fix net-http-persistent timeout detection on Ruby 2.0
Re-enable timeout test because drbrain/net-http-persistent#33 got fixed
in net-http-persistent 2.8
7a38f17
@mislav mislav added a commit to lostisland/faraday that referenced this issue Apr 3, 2013
@mislav mislav fix net-http-persistent timeout detection on Ruby 2.0
Re-enable timeout test because drbrain/net-http-persistent#33 got fixed
in net-http-persistent 2.8
73c9c98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.