Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

connect/read_timeout don't seem to work #127

Closed
mislav opened this Issue · 6 comments

2 participants

@mislav

I'm using :connect_timeout and :read_timeout as params to Excon.new but they don't seem to have effect.

require 'excon'

# a resource that hangs for 10s before responding
url = 'http://localhost:4567/slow'

conn = ::Excon.new(url.to_s, read_timeout: 1, connect_timeout: 1)

puts "requesting..."
started = Time.now

resp = conn.request :method  => 'GET'

p resp.status
p resp.headers

puts "done in %5.2fs" % (Time.now - started)

The request takes 10 seconds and then finishes normally. No exception is thrown, but should be after 1s.

@geemus
Owner

Hmm, not sure off hand. I'm not seeing any obvious problems in the way the code is trying to define timeouts and the like. What ruby and operating system are you using?

@mislav
@geemus geemus closed this issue from a commit
@geemus geemus ensure first read from socket is nonblock
should ensure that timeouts are respected

closes #127
253fdd0
@geemus geemus closed this in 253fdd0
@geemus
Owner

I think the read timeout worked before as long as the timeout occured in the body, but not if it was at the beginning or during the headers. This is due to some difference in how the status/header lines are parsed (for performance reasons). I've changed it so that at least the initial read from the socket is the same as the body reads, which should mean that if the initial portions hangs (as in your case) it should timeout as expected.

@mislav

Yep, it seems to work. The only problem now is that I get the Excon::Errors::SocketError instead of Excon::Errors::Timeout. I have to read the message of the exception to figure out that SocketError was due to a timeout.

@geemus
Owner

@mislav - ah, good. Thanks for the feedback I'll try to correct the message. Then I just need to figure out how to unbreak the build for jruby and it should be releasable...

@geemus
Owner

@mislav - this should fix the error type: d862a33

Still need to figure out whats up with the jruby build though, unfortunately...

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.