Skip to content

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

Merged
khvn26 merged 2 commits into
Flagsmith:mainfrom
abhisrao05:support_keepAlive_timeout
May 15, 2026
Merged

feat: configurable timeout_keep_alive for keep-alive idle connections#188
khvn26 merged 2 commits into
Flagsmith:mainfrom
abhisrao05:support_keepAlive_timeout

Conversation

@abhisrao05
Copy link
Copy Markdown
Contributor

@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
Copy link
Copy Markdown
Contributor

@Zaimwa9 Zaimwa9 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, one small comment on my side otherwise makes sense

Comment thread src/edge_proxy/settings.py Outdated
Copy link
Copy Markdown
Member

@khvn26 khvn26 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@khvn26 khvn26 dismissed Zaimwa9’s stale review May 15, 2026 17:02

This reviewer's comment was addressed; verified by other reviewer

@khvn26 khvn26 merged commit 86bfdfc into Flagsmith:main May 15, 2026
2 checks passed
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.

3 participants