-
Notifications
You must be signed in to change notification settings - Fork 45
fix: add default HTTP request timeout to prevent indefinite hangs #938
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
0ddff77
34cdcb1
d2233c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -85,6 +85,8 @@ def monkey_patched_get_item(self, key): # type: ignore # this interface is a co | |||||||||||||||||||||||||||||||||
| class HttpClient: | ||||||||||||||||||||||||||||||||||
| _DEFAULT_MAX_RETRY: int = 5 | ||||||||||||||||||||||||||||||||||
| _DEFAULT_MAX_TIME: int = 60 * 10 | ||||||||||||||||||||||||||||||||||
| _DEFAULT_CONNECT_TIMEOUT: int = 30 | ||||||||||||||||||||||||||||||||||
| _DEFAULT_READ_TIMEOUT: int = 300 | ||||||||||||||||||||||||||||||||||
| _ACTIONS_TO_RETRY_ON = { | ||||||||||||||||||||||||||||||||||
| ResponseAction.RETRY, | ||||||||||||||||||||||||||||||||||
| ResponseAction.RATE_LIMITED, | ||||||||||||||||||||||||||||||||||
|
|
@@ -588,6 +590,9 @@ def send_request( | |||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| request_kwargs = {**request_kwargs, **env_settings} | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if "timeout" not in request_kwargs: | ||||||||||||||||||||||||||||||||||
| request_kwargs["timeout"] = (self._DEFAULT_CONNECT_TIMEOUT, self._DEFAULT_READ_TIMEOUT) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| response: requests.Response = self._send_with_retry( | ||||||||||||||||||||||||||||||||||
| request=request, | ||||||||||||||||||||||||||||||||||
| request_kwargs=request_kwargs, | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| request_kwargs = {**request_kwargs, **env_settings} | |
| if "timeout" not in request_kwargs: | |
| request_kwargs["timeout"] = (self._DEFAULT_CONNECT_TIMEOUT, self._DEFAULT_READ_TIMEOUT) | |
| response: requests.Response = self._send_with_retry( | |
| request=request, | |
| request_kwargs=request_kwargs, | |
| mutable_request_kwargs: Dict[str, Any] = {**request_kwargs, **env_settings} | |
| if "timeout" not in mutable_request_kwargs: | |
| mutable_request_kwargs["timeout"] = (self._DEFAULT_CONNECT_TIMEOUT, self._DEFAULT_READ_TIMEOUT) | |
| response: requests.Response = self._send_with_retry( | |
| request=request, | |
| request_kwargs=mutable_request_kwargs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change introduces new default-timeout behavior but there isn't a unit test asserting (a) the default timeout is applied when
request_kwargshas notimeout, and (b) an explicit timeout is respected. Adding a focused test would help prevent regressions (especially since this behavior is safety-critical for avoiding indefinite hangs).