Skip to content

feat(upstream): add HTTP/2 PING keepalive for long LLM generation streams - #6281

Open
wuji-labs wants to merge 1 commit into
Wei-Shaw:mainfrom
wuji-labs:feat/http2-long-stream-keepalive
Open

feat(upstream): add HTTP/2 PING keepalive for long LLM generation streams#6281
wuji-labs wants to merge 1 commit into
Wei-Shaw:mainfrom
wuji-labs:feat/http2-long-stream-keepalive

Conversation

@wuji-labs

Copy link
Copy Markdown
Contributor

Background & Motivation

During long-running LLM text/thinking generations (e.g. Gemini high-thinking mode), upstream servers or intermediate proxies/NAT gateways may silently drop idle TCP connections if no data frames are transmitted for a prolonged interval.

By default, Go's \http2.Transport\ has \ReadIdleTimeout: 0\ (active PING probing disabled). When requests land on these silent 'dead connections', clients hang until TCP retransmission timeouts (minutes) or abruptly fail with \502 Bad Gateway\ / \EOF.

Solution

This PR introduces \HTTPUpstreamProfileLongStream\ and proactive HTTP/2 health checking:

  • ReadIdleTimeout: 10s (sends HTTP/2 PING if connection stays silent for 10 seconds)
  • PingTimeout: 5s (evicts and tears down dead pooled connections if PING receives no ACK within 5 seconds)

This prevents long generation streams from getting stuck on dead sockets and ensures transparent connection recovery.

Contributed by WUJI-Labs.

…eams

Long-running LLM inferences (such as high-thinking Gemini models) may experience
silent TCP disconnections across intermediate proxies, NAT gateways, or firewalls
when no data frames are emitted for tens of seconds to minutes.

Go's default http2.Transport sets ReadIdleTimeout=0 (disabling active PING checks).
This commit introduces HTTPUpstreamProfileLongStream with:
- ReadIdleTimeout = 10s
- PingTimeout = 5s

When a pooled H2 connection stays idle for 10s during long streams, active PING frames
are dispatched. Dead connections failing to respond within 5s are proactively evicted,
preventing client generation requests from hanging on dead sockets or failing with EOF/502.

Signed-off-by: WUJI-Labs <zoujincool@gmail.com>
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@wuji-labs

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

1 similar comment
@wuji-labs

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

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