Skip to content

feat: add connection pooling and transient error handling for stale HTTP connections (FME-14487)#336

Open
sanzmauro wants to merge 1 commit intodevelopmentfrom
feature/FME-14487-stale-connection-resilience
Open

feat: add connection pooling and transient error handling for stale HTTP connections (FME-14487)#336
sanzmauro wants to merge 1 commit intodevelopmentfrom
feature/FME-14487-stale-connection-resilience

Conversation

@sanzmauro
Copy link
Copy Markdown
Contributor

@sanzmauro sanzmauro commented Mar 26, 2026

.NET SDK

What did you accomplish?

  • Use SocketsHttpHandler on .NET 5+ with PooledConnectionLifetime (10 min) and PooledConnectionIdleTimeout (30s) to recycle connections before server-side keep-alive timeouts close them.
  • This prevents "The response ended prematurely" (HttpIOException) errors on POST requests caused by stale keep-alive connections. .NET does NOT auto-retry POST requests (non-idempotent) on connection failures, unlike GET requests.
  • Catch transient HttpRequestException with IOException inner exception and log as warning instead of error, allowing retry logic to recover gracefully.

How to test new changes?

  • Run the new integration tests: dotnet test tests/Splitio.Integration-events-tests/ --filter TestCategory=Integration
  • Three test scenarios cover:
    1. Server closes without responding → PostAsync returns failed result
    2. Keep-alive connection goes stale on second request
    3. Retry succeeds on new connection after transient failure

Extra Notes

  • The SocketsHttpHandler configuration is gated behind #if NET5_0_OR_GREATER — older .NET Framework targets continue using HttpClientHandler.
  • A custom PrematureCloseServer (raw TCP) is used in tests since WireMock doesn't support simulating mid-connection closures.

…TTP connections (FME-14487)

Use SocketsHttpHandler on .NET 5+ with PooledConnectionLifetime (10min) and
PooledConnectionIdleTimeout (30s) to prevent stale keep-alive connections causing
"response ended prematurely" errors on POST requests. Also catch transient
HttpRequestException/IOException as a warning instead of error.

Includes integration tests with a PrematureCloseServer to reproduce and verify
the stale connection scenarios.
@sanzmauro sanzmauro requested a review from a team as a code owner March 26, 2026 23:22
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