Skip to content
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

feat: add timeout parameter to AuthorizedSession.request() #406

Merged
merged 2 commits into from
Dec 12, 2019

Conversation

plamut
Copy link
Contributor

@plamut plamut commented Dec 10, 2019

Fixes #396.

This PR is a replacement for #397 that caused a bug in at least one downstream librariy. It contains additional logic that correctly handles timeouts passed as a tuple (the requests library support two different timeout forms - link).

The first commit is identical to the original PR, and all new logic is contained in the commit(s) that follow.

MIND:
A downstream library that is timeout-sensitive might still be affected by the change, because the new explicit timeout parameter changes the semantics of AuthorizedSession.request() . The timeout represents the total allowed time for all requests made behind the scenes (e.g. credentials refresh attempts), as opposed to a previous per-request timeout.

The rationale behind this, however, is that libraries such as BigQuery use AuthorizedSession as their transport, and consider auth_session.request(...) a single operation, even though the latter might consist of multiple requests.

P.S.: On the other hand, and if I read the code correctly, any exiting timeout argument (passed via **kwargs) already applied to the "main" request only, and not to the credentials-related requests. The initial self.credentials.before_request() call had a hard-coded timeout of 120 seconds, while any subsequent credentials refresh calls used self._refresh_timeout, which is actually None by default.

The `request.Request` class also accepts a timeout as a pair
(connect_timeout, read_timeout), and some downstream libraries use
this form.

This commit makes sure that the timeout logic correctly handles
timeouts as a two-tuple.

See also:
https://2.python-requests.org/en/master/user/advanced/#timeouts
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 10, 2019
Copy link
Contributor

@busunkim96 busunkim96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @tswast would you also be able to review this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add timeout parameter to AuthorizedSession.request()
4 participants