Skip to content

Commit 0326918

Browse files
fix: Set PooledConnectionLifetime for DNS re-resolution on long-lived connections (#17)
GrpcChannel.ForAddress creates long-lived HTTP/2 connections via SocketsHttpHandler. By default, PooledConnectionLifetime is infinite, meaning connections are never recycled and DNS is never re-resolved. For clients connecting to load-balanced endpoints (e.g. AWS ALBs), backend IPs can change while the HTTP/2 connection remains healthy, leaving the client stuck on a stale IP. Set PooledConnectionLifetime to 5 minutes so that connections are periodically recycled, triggering fresh DNS resolution.
1 parent 5fc6e77 commit 0326918

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

Spice/src/Flight/SpiceFlightClient.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ private static GrpcChannelOptions GetGrpcChannelOptions(string? appId, string? a
5656
// Configure HttpHandler for TLS on macOS (.NET 8.0+)
5757
var handler = new SocketsHttpHandler
5858
{
59-
EnableMultipleHttp2Connections = true
59+
EnableMultipleHttp2Connections = true,
60+
// Force periodic connection recycling to trigger DNS re-resolution.
61+
// Without this, HTTP/2 connections are kept alive indefinitely and
62+
// the client can get stuck on stale IPs when backend targets change
63+
// (e.g. AWS ALB target rotation).
64+
PooledConnectionLifetime = TimeSpan.FromMinutes(5),
6065
};
6166
options.HttpHandler = handler;
6267
}
@@ -74,7 +79,12 @@ private static GrpcChannelOptions GetGrpcChannelOptions(string? appId, string? a
7479
{
7580
messageHandler = new SocketsHttpHandler
7681
{
77-
EnableMultipleHttp2Connections = true
82+
EnableMultipleHttp2Connections = true,
83+
// Force periodic connection recycling to trigger DNS re-resolution.
84+
// Without this, HTTP/2 connections are kept alive indefinitely and
85+
// the client can get stuck on stale IPs when backend targets change
86+
// (e.g. AWS ALB target rotation).
87+
PooledConnectionLifetime = TimeSpan.FromMinutes(5),
7888
};
7989
}
8090
else

0 commit comments

Comments
 (0)