lostisland / faraday

Simple, but flexible HTTP client library, with support for multiple backends.
https://lostisland.github.io/faraday
MIT License
5.71k stars 972 forks source link

Difference between `timeout` and `open_timeout` #1469

Closed Yu-Chieh-Henry-Yang closed 1 year ago

Yu-Chieh-Henry-Yang commented 1 year ago

We have these comment in the codebase: https://github.com/lostisland/faraday/blob/1a5b794b88ba897afca24e914b9b19297bc80473/lib/faraday/options/env.rb#L18-L19

:timeout says open/read timeout Integer in seconds :open_timeout says read timeout Integer in seconds

Question 1: Does this mean timeout includes open_timeout? For example, if everything times out at the limit and we configured to have 4 seconds open_timeout and 6 seconds timeout, do we actually wait only 6 seconds (which includes the 4 seconds) or do we actually wait 4+6 = 10 seconds?

Question 2: :open_timeout is called "open" timeout, why does it says read timeout Integer in seconds instead of something like timeout Integer in seconds for opening connection?

Thank you very much.

iMacTia commented 1 year ago

Hi @Yu-Chieh-Henry-Yang, apologies if this is confusing.

timeout is a setting for the whole request and thus is calculated for both opening the connection and reading the response (open/read). If the request hasn't finished after this threshold (even if some data have been received in the meantime), then it will timeout.

OTOH open_timeout is only used to time the opening of the connection (i.e. time to first byte received). If the server replies with some data before this threshold, then no timeout will be raised (unless obviously the requests goes over the timeout threshold.

iMacTia commented 1 year ago

You're right though the description for open_timeout seems incorrect! It should be :open_timeout - open timeout Integer in seconds

iMacTia commented 1 year ago

There are 2 more types of timeout, I've added a comment to explain them all to your PR 👍 Thank you for addressing this 🙏 !

Yu-Chieh-Henry-Yang commented 1 year ago

Thanks for the explanation @iMacTia , I will continue the conversation in my PR. 🙏