Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Set default timeout for all the HTTP requests #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 19, 2017
Merged

Set default timeout for all the HTTP requests #320

merged 4 commits into from
Jan 19, 2017

Conversation

i-maravic
Copy link
Contributor

This will avoid having hanging connections when using Google API calls.

In case the user have set default socket timeout, that value is used instead of default.

@googlebot
Copy link
Collaborator

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Dec 26, 2016
@i-maravic
Copy link
Contributor Author

I signed it!

@i-maravic
Copy link
Contributor Author

@fabriziodemaria

@i-maravic
Copy link
Contributor Author

@jonparrott Could you take a look at this PR please?

This will avoid having hanging connections when using Google API calls.
@theacodes
Copy link
Contributor

5 minutes seems way too high. App Engine will terminate requests after 60 seconds.

@i-maravic
Copy link
Contributor Author

@jonparrott I wanted to be conservative.

I've changed it to 60s now.

@i-maravic i-maravic changed the title Set default timeout of 5 minutes for all the HTTP requests Set default timeout for all the HTTP requests Jan 11, 2017
@theacodes
Copy link
Contributor

@i-maravic I guess my concern here is that I don't like the idea of using any library-specific timeout that the user doesn't explicitly set. It's surprising behavior. What prompted this change? Can I get some more context to better understand what problem this is trying to solve?

@i-maravic
Copy link
Contributor Author

@jonparrott We're using google-api-python-client when running periodic (hourly or daily) batch jobs for uploading to BigQuery and reading/writing to Google Cloud Storage. All the periodic jobs are being executed in Docker containers.

Recently we've experienced issues with those jobs hanging forever without making any progress. After doing some investigation we detected that the code making requests to Google APIs (aka. google-api-python-client) is hanging forever while waiting something to read from TCP socket. This was surprising behaviour for us.

After doing even more digging we discovered that Docker had some weird networking issues, which were causing this in the first place. We're not 100% sure how to reproduce Docker issue though, but restarting the Docker service mitigated a lot of problems we're experiencing.

I fell that library doing HTTP requests should set a sane default timeout for doing HTTP requests, because we could easily avoid issues like this in the future. I would argue that this is what most of the users would like to have any how.

I would also like to point out that you already have code in your lib, which is dealing with Timeout exceptions that might be thrown from the HTTP requests and do the retries accordingly.

I know that you're not using requests library, but there is very nice explanation why all production code using it should set timeouts for all the HTTP requests it's doing.

@theacodes
Copy link
Contributor

@i-maravic I see, okay.

I need the CLA bot to verify your signature status before I can merge.

@i-maravic
Copy link
Contributor Author

I work for Spotify. Spotify should have signed the CLA.

@theacodes
Copy link
Contributor

@i-maravic gotcha.

@lukesneeringer @landrito I'd appreciate if one of you could chime in and let me know your thoughts before I merge this.

@lukesneeringer
Copy link
Contributor

A 60 second default timeout seems reasonable to me, and it is easy enough to override. LGTM.

@theacodes
Copy link
Contributor

@lukesneeringer thanks for chiming in!

@i-maravic okay, so it looks like this is going to happen, can I ask two things of you:

  1. Is it possible to add tests or assertions to existing tests to cover this?
  2. This timeout only applies to the http object used to fetch discovery documents. Do you want to apply the timeout to the http object used to make actual API requests as well?

@i-maravic
Copy link
Contributor Author

@jonparrott Sounds like reasonable asks.

Could you point me out where is the http object for actual API requests constructed?

@theacodes
Copy link
Contributor

@i-maravic
Copy link
Contributor Author

i-maravic commented Jan 19, 2017

@jonparrott Now the default timeout is applied to all discovery and API requests (auth or not)

Hopefully I did catch all httplib2.Http() instantiations in the lib.

@theacodes
Copy link
Contributor

@i-maravic this looks good, one last question:

Do you want to pass in timeout to authorized_http here? Otherwise, the authorized http instance won't have the timeout.

@i-maravic
Copy link
Contributor Author

@jonparrott authorized_http gets timeout set here

@theacodes
Copy link
Contributor

@i-maravic gotcha. Alright, this LGTM. Thanks!

@theacodes theacodes merged commit 2243529 into googleapis:master Jan 19, 2017
@i-maravic i-maravic deleted the patch-2 branch January 19, 2017 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: no This human has *not* signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants