Skip to content

feat: configurable timeout_keep_alive for keep-alive idle connections#188

Open
abhisrao05 wants to merge 1 commit intoFlagsmith:mainfrom
abhisrao05:support_keepAlive_timeout
Open

feat: configurable timeout_keep_alive for keep-alive idle connections#188
abhisrao05 wants to merge 1 commit intoFlagsmith:mainfrom
abhisrao05:support_keepAlive_timeout

Conversation

@abhisrao05
Copy link
Copy Markdown

@abhisrao05 abhisrao05 commented May 3, 2026

Problem

Flagsmith SDK clients (default poll interval: 10s) intermittently see ConnectionResetError on the pooled /api/v1/environment-document/ request:

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='10.12.40.89', port=80):
Max retries exceeded with url: /api/v1/environment-document/
(Caused by ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')))

Root cause

uvicorn's timeout_keep_alive defaults to 5s. Any HTTP intermediary in front of edge-proxy — load balancer, proxy, or the SDK's own urllib3 connection pool that holds an idle connection longer than 5s ends up reusing a half-closed socket on its next request, surfacing as connection reset. Polling SDKs are especially exposed: a 10s poll interval against a 5s server keep-alive guarantees almost every client's pooled connection is stale.

Fix

Surface timeout_keep_alive through edge-proxy's existing config (config.json / env), so operators can raise it past their client poll interval (or LB idle timeout). Default unchanged at 5s — purely additive.

Changes

  • src/edge_proxy/settings.py: new timeout_keep_alive: int = 5 on ServerSettings
  • src/edge_proxy/main.py: pass timeout_keep_alive=settings.server.timeout_keep_alive to uvicorn.run()

Test plan

  • Unit: setting loads from config.json (`{"server": {"timeout_keep_alive": 2}}` → `timeout_keep_alive=2` on the AppConfig instance)
  • Integration: with `timeout_keep_alive=2`, server closes idle keep-alive connections at t≈2.08s
  • Integration: with `timeout_keep_alive=20`, server closes at t≈20.09s
  • Default behavior unchanged when not overridden in config

@abhisrao05 abhisrao05 requested a review from a team as a code owner May 3, 2026 21:23
@abhisrao05 abhisrao05 requested review from gagantrivedi and removed request for a team May 3, 2026 21:23
@abhisrao05 abhisrao05 changed the title feat: configurable timeout_keep_alive for keep-alive idle connections Feat: configurable timeout_keep_alive for keep-alive idle connections May 3, 2026
@abhisrao05 abhisrao05 changed the title Feat: configurable timeout_keep_alive for keep-alive idle connections feat: configurable timeout_keep_alive for keep-alive idle connections May 3, 2026
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.

1 participant