Skip to content

Bound pooled connection lifetime (fixes stale-connection failures) - #38

Open
mmalkhatib wants to merge 1 commit into
mainfrom
muhannad/bound-pooled-connection-lifetime
Open

Bound pooled connection lifetime (fixes stale-connection failures)#38
mmalkhatib wants to merge 1 commit into
mainfrom
muhannad/bound-pooled-connection-lifetime

Conversation

@mmalkhatib

Copy link
Copy Markdown
Contributor

Summary

AddApiClient's AddHttpClient<...>() calls never configured a SocketsHttpHandler, so PooledConnectionLifetime defaulted to Timeout.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 with StatusCode=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 PooledConnectionLifetime to 2 minutes forces a fresh connection (and fresh DNS resolution) at least that often.

Test plan

  • dotnet build — 0 errors
  • Bump consumers to the new version and confirm the StatusCode=0 errors stop

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.
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository: simplify9/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4373be37-1ebe-4be8-8a92-d43df18d5947


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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