fix: Configure HTTP/2 keep-alive for faster detection of stale connections - #71
Closed
phillipleblanc wants to merge 1 commit into
Closed
fix: Configure HTTP/2 keep-alive for faster detection of stale connections#71phillipleblanc wants to merge 1 commit into
phillipleblanc wants to merge 1 commit into
Conversation
…tions Tonic resolves DNS only when establishing a new connection. Since HTTP/2 connections are long-lived and multiplexed, a client connecting to a load-balanced endpoint (e.g. AWS ALB) can get stuck on a stale IP when backend targets change. Configure HTTP/2 keep-alive on the tonic Endpoint so that dead connections are detected quickly and tonic's built-in Reconnect layer re-establishes a fresh connection with a new DNS lookup.
There was a problem hiding this comment.
Pull request overview
This PR configures tonic Endpoint HTTP/2/TCP keep-alive settings for Flight SQL channels to detect dead/stale backend connections sooner (e.g., after load balancer target/IP changes) and trigger reconnects (and therefore fresh DNS resolution).
Changes:
- Add HTTP/2 keep-alive interval + timeout configuration on the Flight channel
Endpoint. - Enable keep-alive probes while idle and set a TCP keepalive interval as a fallback.
Comment on lines
+43
to
+47
| endpoint = endpoint | ||
| .keep_alive_while_idle(true) | ||
| .http2_keep_alive_interval(Duration::from_secs(60)) | ||
| .keep_alive_timeout(Duration::from_secs(20)) | ||
| .tcp_keepalive(Some(Duration::from_secs(60))); |
There was a problem hiding this comment.
These keep-alive values are hard-coded and will apply to every SDK consumer, including those running locally or in environments where periodic idle PINGs are undesirable. Consider promoting the durations to named constants (or exposing them as optional SpiceClientBuilder/config knobs with sensible defaults) so users can tune/disable the behavior without patching the SDK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Tonic resolves DNS only when establishing a new connection. Since HTTP/2 connections are long-lived and multiplexed, a client connecting to a load-balanced endpoint (e.g. AWS ALB) can get stuck on a stale IP when backend targets change.
Fix
Configure HTTP/2 keep-alive settings on the tonic
Endpoint:http2_keep_alive_interval(60s)— send HTTP/2 PING frames every 60 secondskeep_alive_timeout(20s)— drop connection if PING isn't acknowledged within 20 secondskeep_alive_while_idle(true)— probe even when no active RPCstcp_keepalive(60s)— OS-level TCP keepalive as a fallbackWhen a keep-alive probe fails (because the backend IP is no longer valid), tonic's built-in
Reconnectlayer drops the dead connection and establishes a new one, which triggers a fresh DNS lookup.Related