-
Notifications
You must be signed in to change notification settings - Fork 361
fix: add configurable HTTP timeout and preserve error context #318
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 all commits
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 |
|---|---|---|
|
|
@@ -19,6 +19,14 @@ | |
| _http_client = httpx.Client(http2=True) | ||
|
|
||
|
|
||
| def set_http_timeout(timeout: float) -> None: | ||
| """ | ||
| Reconfigure the module-level HTTP client with a custom timeout (in seconds). | ||
| """ | ||
| global _http_client | ||
| _http_client = httpx.Client(http2=True, timeout=timeout) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Old HTTP client not closed, leaking connectionsMedium Severity
|
||
|
|
||
|
|
||
| def overloadHeaders(method: str, headers: dict) -> dict: | ||
| if headers is None: | ||
| headers = dict() | ||
|
|
@@ -61,8 +69,8 @@ def request(endpoint: str, method: str, headers=None, data=None): | |
| except ValueError: | ||
| return resp.text | ||
|
|
||
| except httpx.RequestError: | ||
| raise PolyApiException(error_msg="Request exception!") | ||
| except httpx.RequestError as exc: | ||
| raise PolyApiException(error_msg=f"Request exception: {exc}") from exc | ||
|
|
||
|
|
||
| def post(endpoint, headers=None, data=None): | ||
|
|
||


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.
Per-instance timeout parameter actually mutates global state
High Severity
The
timeoutparameter onClobClient.__init__suggests per-instance configuration, butset_http_timeoutreplaces a module-level global_http_clientshared by all instances. Creating a secondClobClientwith a different (or no) timeout silently overrides the first client's timeout. Ironically, this can reintroduce the exact duplicate-order problem the PR aims to fix — a user setstimeout=30on one client, then another component instantiates a default client, resetting the timeout to httpx's default.Additional Locations (1)
py_clob_client/http_helpers/helpers.py#L21-L27