Question

Since Faraday doesn't have documentation, I wasn't able to find it out anywhere. What is "timeout" and what "open timeout" in Faraday?

Was it helpful?

Solution

If you look at the source code at https://github.com/lostisland/faraday/blob/master/lib/faraday/request.rb then you'll see:

#   :timeout      - open/read timeout Integer in seconds
#   :open_timeout - read timeout Integer in seconds

Not very helpful, perhaps? Well, if you look at Faraday's Net::HTTP adapter at https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter/net_http.rb, you'll see:

http.read_timeout = http.open_timeout = req[:timeout] if req[:timeout]
http.open_timeout = req[:open_timeout]                if req[:open_timeout]

So Faraday's open_timeout is equivalent to Net::HTTP's open_timeout which is documented as:

Number of seconds to wait for the connection to open. Any number may be used, including Floats for fractional seconds. If the HTTP object cannot open a connection in this many seconds, it raises a TimeoutError exception.

And Faraday's timeout is equivalent to Net::HTTP's read_timeout which is documented as:

Number of seconds to wait for one block to be read (via one read(2) call). Any number may be used, including Floats for fractional seconds. If the HTTP object cannot read data in this many seconds, it raises a TimeoutError exception.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top