Bound pooled connection lifetime (fixes stale-connection failures) - #38
Open
mmalkhatib wants to merge 1 commit into
Open
Bound pooled connection lifetime (fixes stale-connection failures)#38mmalkhatib wants to merge 1 commit into
mmalkhatib wants to merge 1 commit into
Conversation
AddApiClient's AddHttpClient<...>() calls never configured a SocketsHttpHandler, so PooledConnectionLifetime defaulted to Timeout.InfiniteTimeSpan - a pooled connection is only ever recycled by HttpClientFactory's own handler rotation (every 2 minutes by default), which doesn't help a connection that's mid-use or was recently reused. A connection that goes stale on the network side (NAT/conntrack entry expiring, a load balancer dropping an idle socket) fails silently on its next reuse instead of erroring where the network actually dropped it. Confirmed live in production: Ship's calls to Lookups (traceType lookups via ProcessAddedShipmentTrace) were failing with StatusCode=0 at high volume, while a fresh raw HTTP request to the exact same endpoint from the exact same pod succeeded in 10-20ms every time - ruling out the app, the query, and the network path itself, and pointing squarely at a stale pooled connection. Bounding PooledConnectionLifetime to 2 minutes forces a fresh connection (and fresh DNS resolution) at least that often, so a connection can never go stale for longer than this window before being discarded and replaced.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Repository: simplify9/coderabbit/.coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
AddApiClient'sAddHttpClient<...>()calls never configured aSocketsHttpHandler, soPooledConnectionLifetimedefaulted toTimeout.InfiniteTimeSpan. A connection that goes stale on the network side (NAT/conntrack entry expiring, a load balancer dropping an idle socket) fails silently on its next reuse instead of erroring where the network actually dropped it.Confirmed live in production traxis-ship: calls to Lookups (
ProcessAddedShipmentTrace) were failing at high volume withStatusCode=0, while a fresh raw HTTP request to the exact same endpoint from the exact same pod succeeded in 10-20ms every time — ruling out the app, the query, and the network path, and pointing squarely at a stale pooled connection.Bounding
PooledConnectionLifetimeto 2 minutes forces a fresh connection (and fresh DNS resolution) at least that often.Test plan
dotnet build— 0 errorsStatusCode=0errors stop