Skip to content

fix: apply http_connect_timeout/http_read_timeout to async requests - #168

Closed
pcbeingused33 wants to merge 3 commits into
growthbook:mainfrom
pcbeingused33:fix/async-http-timeouts
Closed

pcbeingused33 wants to merge 3 commits into
growthbook:mainfrom
pcbeingused33:fix/async-http-timeouts

Conversation

@pcbeingused33

Copy link
Copy Markdown

Problem

Options.http_connect_timeout and Options.http_read_timeout are passed by GrowthBookClient to its feature repository, but the async request paths never read them: _fetch_and_decode_async (features GET) and _fetch_and_decode_post_async (remote-eval POST) both open aiohttp.ClientSession() with no timeout. Setting the options on the async client therefore has no effect, and requests fall back to aiohttp's defaults (5 minutes total).

The sync paths (_get / _post, and the GrowthBook constructor) do apply them, but only when both values are set, so configuring just one of the two is silently ignored.

Fix

  • Both async paths now create the session with an aiohttp.ClientTimeout when at least one of the options is set: http_connect_timeout maps to sock_connect and http_read_timeout to sock_read. The timeout starts from aiohttp's own default (aiohttp.client.DEFAULT_TIMEOUT) and only the configured fields are overridden, so the overall request limit (and the default socket connect limit when only the read timeout is set) stays in place. With neither option set, the session is created exactly as before.
  • The sync paths build the urllib3 Timeout through one shared helper that accepts each value on its own, and the GrowthBook constructor forwards each option independently.

Behaviour is unchanged for anyone who sets neither option, or who sets both on the sync client.

Tests

New tests/test_http_timeouts.py: the async GET and POST paths are run against a stand-in ClientSession that records its constructor arguments (connect and read values reach the session; with one or both options set, every field that was not configured still equals aiohttp's default, including total; no timeout argument without options), and the sync path is checked for each combination through a patched PoolManager. Seven of these fail before the change. pytest -q, mypy and the CI flake8 selection pass.


This PR was prepared with the help of an AI coding assistant (Claude Code).

pcbeingused33 and others added 2 commits November 28, 2026 08:20
The aiohttp sessions used by the async feature fetch and the remote-eval
POST were created without a timeout, so the options had no effect on
GrowthBookClient. The sync paths only honoured them when both were set.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A bare aiohttp.ClientTimeout(sock_connect=..., sock_read=...) replaces
aiohttp's default timeout, dropping the overall request limit and the
default socket connect limit. Start from the defaults and override only
the options that are set.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5 · Fix the sync constructor order before merging so automatic loads honor the configured timeout.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect GrowthBook’s feature-fetch and remote-evaluation requests.

Fix the sync constructor order before merging so automatic loads honor the configured timeout.

Reviews (1) · Last reviewed commit: "fix: keep aiohttp default timeouts for u..." · Reviewed by Greptile

Comment thread growthbook/growthbook.py Outdated
Comment on lines 1117 to 1120
if http_connect_timeout is not None:
feature_repo.http_connect_timeout = http_connect_timeout
if http_read_timeout is not None:
feature_repo.http_read_timeout = http_read_timeout

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Startup ignores configured timeouts

The new one-sided timeout support still fails when GrowthBook loads during construction. With a fresh feature_repo, enabling streaming, stale_while_revalidate, or remote_eval calls load_features() before these assignments. That request creates PoolManager(timeout=None). Later requests reuse the same pool, so the configured timeout never applies and requests can wait indefinitely.

Move these assignments before plugins and automatic loads, and add a constructor-level test.

Knowledge Base Used: Client lifecycle and feature refresh

Prompt To Fix With AI
This is a comment left during a code review.
Path: growthbook/growthbook.py
Line: 1117-1120

Comment:
**Startup ignores configured timeouts**

The new one-sided timeout support still fails when `GrowthBook` loads during construction. With a fresh `feature_repo`, enabling `streaming`, `stale_while_revalidate`, or `remote_eval` calls `load_features()` before these assignments. That request creates `PoolManager(timeout=None)`. Later requests reuse the same pool, so the configured timeout never applies and requests can wait indefinitely.

Move these assignments before plugins and automatic loads, and add a constructor-level test.

**Knowledge Base Used:** [Client lifecycle and feature refresh](https://app.greptile.com/-/switch-tenant?tenant=growthbook&next=%2Fcustom-context%2Fknowledge-base%2Fgrowthbook%2Fgrowthbook-python%2F-%2Fdocs%2Fclient-lifecycle-and-feature-refresh.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@pcbeingused33

Copy link
Copy Markdown
Author

The constructor now applies the configured HTTP timeouts before its first automatic feature load. The regression checks that the initial remote-eval POST uses a pool with the configured timeouts and that a subsequent refresh reuses that same pool. It covers each timeout independently and both together.

This comment was drafted with Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants