tpitale/legato

How to set HTTP timeout ?

Closed this issue · 4 comments

Hi !

Great library, we've been using it in production for quite a while and it powers an important feature, so thanks !

However, I've recently encountered a problem where a non-reachable google server caused all our servers to hang forever. Is there any way to set a non-default HTTP timeout value ? I've tried setting options on the OAuth2::Client instance but it had no effect, and I can't seem to find my way through the many indirections...

I'll take a look. I feel like I've done this before, but can't recall offhand.

When you create your OAuth2::Client instance it yields the Faraday builder (https://github.com/intridea/oauth2/blob/master/lib/oauth2/client.rb#L26). An example of this is found in their client specs, specifically here. From there I imagine you can set whatever HTTP options you'd like.

Thanks @proby! @MGPalmer I hope that helps, just comment if you want me to reopen.

@proby @tpitale thanks guys - it turns out the builder is not necessary, here's what works for me:

      oauth_client = OAuth2::Client.new("", "", {
         :authorize_url => 'https://accounts.google.com/o/oauth2/auth',
         :token_url     => 'https://accounts.google.com/o/oauth2/token',
         :connection_opts => {
           :request => {
              # the timeout is important because the default is very long (5m?), and a non-reachable google server
              # then means our servers hang as well, quickly using up all instances...
              :timeout      => 5,
              :open_timeout => 5,
            }
         }
      })