Repository navigation
fix: apply http_connect_timeout/http_read_timeout to async requests - #168
pcbeingused33 wants to merge 3 commits into
Conversation
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>
[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 |
| 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 |
There was a problem hiding this 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
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.|
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. |
Problem
Options.http_connect_timeoutandOptions.http_read_timeoutare passed byGrowthBookClientto 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 openaiohttp.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 theGrowthBookconstructor) do apply them, but only when both values are set, so configuring just one of the two is silently ignored.Fix
aiohttp.ClientTimeoutwhen at least one of the options is set:http_connect_timeoutmaps tosock_connectandhttp_read_timeouttosock_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.Timeoutthrough one shared helper that accepts each value on its own, and theGrowthBookconstructor 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-inClientSessionthat 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, includingtotal; notimeoutargument without options), and the sync path is checked for each combination through a patchedPoolManager. Seven of these fail before the change.pytest -q,mypyand the CIflake8selection pass.This PR was prepared with the help of an AI coding assistant (Claude Code).