Skip to content

fix: Configure HTTP/2 keep-alive for faster detection of stale connections - #71

Closed
phillipleblanc wants to merge 1 commit into
trunkfrom
phillipleblanc/fix-dns-re-resolution
Closed

fix: Configure HTTP/2 keep-alive for faster detection of stale connections#71
phillipleblanc wants to merge 1 commit into
trunkfrom
phillipleblanc/fix-dns-re-resolution

Conversation

@phillipleblanc

Copy link
Copy Markdown
Contributor

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 seconds
  • keep_alive_timeout(20s) — drop connection if PING isn't acknowledged within 20 seconds
  • keep_alive_while_idle(true) — probe even when no active RPCs
  • tcp_keepalive(60s) — OS-level TCP keepalive as a fallback

When a keep-alive probe fails (because the backend IP is no longer valid), tonic's built-in Reconnect layer drops the dead connection and establishes a new one, which triggers a fresh DNS lookup.

Related

…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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 thread src/tls.rs
Comment thread src/tls.rs
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)));

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

2 participants