Skip to content

[Tests] Setup needed for Connection Pool reliability testing #3667

Open

Description

@cheenamalhotra

Connection Pool reliability testing is needed for pool validation, specially with the new incoming connection pool design work, led by @mdaigle #3356.

This test framework should cover connection pool behaviors under stress, high CPU load and concurrent runs. Some of the initial work came through PR #3632 (ConnectionPoolStressTest) but is incomplete in its current state. It needs a new home, reworked and redesigned to do more elaborate testing.

Activity

  1. added
    Area\Tests
    Area\Connection Pooling
    on Oct 7, 2025
  2. moved this from To triage to Backlog in SqlClient Boardon Nov 26, 2025
  3. federico-paganini commented on Aug 24, 2026

    @federico-paganini

    A managed cloud egress can silently drop an idle outbound TCP flow: Azure Load Balancer, for example, drops flows silently at its 4-minute default idle timeout unless TCP reset is enabled. A pooled connection dropped that way is the classic reliability failure this issue exists for: the pool cannot tell the half-open socket from a live one, the next command's first write is black-holed, and the command fails at CommandTimeout + 5 s (the attention timeout) with Win32 error 258. We reproduced it deterministically in a lab with a per-flow black-hole (#1530). It is self-healing, but very user-visible, and impossible to catch in a conventional test suite, which is why we'd like to help with this one.

    Edited 2026-09-26: the first version of this paragraph attributed our production stalls (40–67 s after idle windows) to this mechanism and equated the stall with the TCP keep-alive detection window. Both were wrong. Our production stalls were Azure SQL serverless resumes: across the 470 stalls we examined, every burst leader failed at connect at ~40 s, and none was a command-phase timeout. And the driver's keep-alive works in the pool's favour: it is hardcoded at 30 s idle / 1 s interval, so on Linux (9 probes by default) a socket dead for longer than ~39 s is closed by the kernel and discarded at checkout. A half-open connection therefore only reaches a caller when the drop happened within ~39 s of checkout. The mechanism itself stands as described and is lab-reproduced; we have not observed it in our production.

    We have two assets that seem to fit the framework this issue asks for, and we're willing to implement them:

    1. A deterministic idle-eviction probe. We built one to validate Connection Idle Timeout (#4295) on 7.1.0-preview2 (re-run on 7.1.0: identical) against the default (WaitHandleDbConnectionPool) pool, SQL Server 2022 in Docker. Results:

    case (per process) Connection Idle Timeout idle gap outcome
    switch at default (true) 4 s 20 s REUSED — keyword inert
    switch false 4 s 20 s EVICTED
    switch false (control) 30 s 5 s REUSED — young connection kept
    switch false, keyword absent — 340 s EVICTED — the 300 s default fires
    switch false, explicit 0 0 340 s REUSED — 0 disables eviction

    2. A "silent middlebox drop" fixture. A TCP proxy (or an nftables drop rule) between client and server that stops forwarding without FIN/RST, containerized, so tests can fabricate half-open pooled connections on demand. This turns the recurring "unreproducible transport error" class of reports into assertable behavior: after a silent drop, checkout serves the dead connection and the next command fails at CommandTimeout + 5 s — or, once the drop is older than the ~39 s keep-alive window, the pool discards the connection at checkout instead.

    Three measurement traps we hit while building the probe — a reliability suite needs to encode all three, because each one produced a coherent-looking wrong result before we caught it:

    • LocalAppContextSwitches caches switch values in statics on first read, so a sequential in-process test matrix silently tests the first case's value N times. One process per case.
    • @@SPID is not a connection identity: the server recycles it as soon as a session closes, so a fresh connection can read as "reused".
    • sys.dm_exec_sessions.login_time is not one either: sp_reset_connection refreshes it on pooled reuse, so a plain reuse reads as a new login. The reliable discriminator is SqlConnection.ClientConnectionId.

    We also tested whether idle eviction exempts connections retained by Min Pool Size — it does not: with Min Pool Size=2 and a 4 s timeout, both retained connections were gone after a 20 s idle gap (0/2 ClientConnectionId overlap, repeated runs). We have since distinguished the two (7.1.0-preview2, -preview3 and 7.1.0, identical results): neither. Nothing at or below the minimum is destroyed or replaced in the background; expiry is enforced at checkout, where a caller that reaches an expired retainee gets it swapped synchronously for a fresh connection (one cold open: 5–20 ms locally, versus ~0 ms warm), and the floor does not re-warm by itself. So no aged connection reaches a command, which is the property that matters against a silent middlebox; the cost is that Min Pool Size keeps its count guarantee and loses its warm one.

    If this direction is useful, we'd take a first PR scoped to the probe harness (wherever you prefer it to live — ManualTests?), aligned with the #3356 redesign. Happy to align on design here first.

  4. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

  5. github-actions commented on Sep 17, 2026

    @github-actions

    🔍 Triage Summary (on-demand re-triage)

    Check Result
    Issue type Task
    Environment Not applicable (Task/test-infrastructure request, not a bug report)
    Area Area\Connection Pooling (also touches Area\Tests)
    Duplicates Potentially related: #3821, #3822
    Regression Not applicable

    Analysis

    This is a Task requesting a connection pool reliability test framework (stress/high-CPU/concurrent scenarios), tied to the pool redesign in #3356 and initial work in PR #3632. A contributor (@federico-paganini) has proposed two concrete assets to build toward this: a deterministic idle-eviction probe (validating Connection Idle Timeout behavior against WaitHandleDbConnectionPool) and a "silent middlebox drop" fixture that simulates half-open pooled connections (relevant to environments like Azure Container Apps where idle TCP is silently dropped). They also flagged useful measurement pitfalls (static caching in LocalAppContextSwitches, unreliable @@SPID/login_time as connection identity, using SqlConnection.ClientConnectionId instead). Priority: P2 — valuable test-infrastructure work, not blocking a release, but unblocks safer validation of the pool redesign.

    Next Steps

    • Maintainers should respond to @federico-paganini's proposal and confirm scope/location (e.g., whether the probe harness belongs in ManualTests or a new dedicated reliability-test project) before a PR is opened, per their request to "align on design here first."
    • Review Test | SqlConnectionReliabilityTests are flaky #3821 (SqlConnectionReliabilityTests flaky) and Make SqlConnectionReliabilityTest more reliable and re-enable #3822 (making that reliability test more reliable) — this new framework should coordinate with or supersede those efforts rather than duplicate them.
    • Once scope is agreed, recommend assigning to Copilot coding agent (or the contributor) to implement: (1) the idle-eviction probe using ClientConnectionId for connection identity assertions, one-process-per-case to avoid LocalAppContextSwitches static caching issues, and (2) the silent-drop TCP proxy/nftables fixture, aligned with the ChannelDbConnectionPool/WaitHandleDbConnectionPool designs described in the connection-pooling instructions.

    Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.

    Generated by SqlClient Issue Auto-Triage for #3667 · copilot · auto · 55.6 AIC · ⌖ 13.1 AIC · ⊞ 11.9K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area\Connection PoolingArea\Tests

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions