Skip to content

Commit

Permalink
Add default timeout
Browse files Browse the repository at this point in the history
This adds a default connect and read timeout value for all usage of
Requests. This is to solve a long-standing issue where some systems do
not have a sufficiently low default value.

Personally, I'd want these values to be much lower, but a 10 second
connection timeout and a 30 second read timeout seem like they should be
enough to avoid problems for the edge cases of users while also not
being so large that they're basically ineffective.

Closes #3070
  • Loading branch information
sigmavirus24 committed May 21, 2024
1 parent 970e8ce commit 754980b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ dev

- \[Short description of non-trivial change.\]

**Security**
- Add a default timeout value to Requests. The default connect timeout is 10.0
seconds and the default read timeout is 30.0 seconds. (#3070)

2.32.1 (2024-05-20)
-------------------

Expand Down
6 changes: 5 additions & 1 deletion src/requests/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
preferred_clock = time.time


# (connect timeout, read timeout)
_DEFAULT_TIMEOUT = (10.0, 30.0)


def merge_setting(request_setting, session_setting, dict_class=OrderedDict):
"""Determines appropriate setting for a given request, taking into account
the explicit setting on that request, and the setting in the session. If a
Expand Down Expand Up @@ -582,7 +586,7 @@ def request(

# Send the request.
send_kwargs = {
"timeout": timeout,
"timeout": timeout if timeout is not None else _DEFAULT_TIMEOUT,
"allow_redirects": allow_redirects,
}
send_kwargs.update(settings)
Expand Down

0 comments on commit 754980b

Please sign in to comment.