Visitar URL original
TLS handshake has no timeout, one stalled handshake can stop a pool from creating any new connections indefinitely. · Issue #4834 · dotnet/SqlClient · GitHub
Skip to content

TLS handshake has no timeout, one stalled handshake can stop a pool from creating any new connections indefinitely. #4834

Description

@LukeButters

Describe the bug

The TLS handshake has no timeout, and the underlying network stream has no timeout. This means, should a TCP connection go down without a FIN/RST being sent (which can happen) during the TLS handshake, then

  • That connection will never open and hang indefinitely.
  • Since only one "worker/thread" can open a connection for the pool at a time, the pool can never grow as it is blocked waiting for that stuck connection to complete opening the connection.

To reproduce

The issue has been replicated in my own fork. You can run the two tests to see the issue and the expected behavior with a fix applied.

In short, the tests:

  1. Opens a connection to the DB via a Port forwarder. This probably does not need to be done.
  2. Instructs the test to "pause" all TCP connections just before the TLS handshake. The pause here simulates a TCP disconnect in which no FIN/RST packets are sent.
  3. Another connection is opened.
  4. Just before the TLS handshake, the TCP connection (already opened) is paused.
  5. Since the stream has no timeout and no cancellation token is passed into tls handshake, the open connection hangs forever.
  6. One of the test demos shows that once we reach this stage, we can not create a new connection, even if the port forwarder does NOT pause any connections.

Expected behavior

The existing Timeout as set in SqlConnectionStringBuilder.ConnectTimeout should be respected. In the case described above, an exception should be thrown when the timeout is reached. After that, new connections should eventually be possible.

The PR and tests demonstrate enabling a fix, and these tests passing.

Further technical details

Demonstrated on Main, affects version 7.1.1

Additional context

Activity

  1. added theissue type on Oct 13, 2026
  2. changed the title [-]TLS handshake has no timeout, One stalled handshake can stop a pool from creating any connections indefinitely.[/-] [+]TLS handshake has no timeout, one stalled handshake can stop a pool from creating any new connections indefinitely.[/+] on Oct 13, 2026
  3. github-actions commented on Oct 13, 2026

    @github-actions

    🔍 Triage Summary

    Check Result
    Issue type Bug
    Environment ⚠️ Missing: SqlClient version (only "Main" noted), .NET target framework, SQL Server version, OS, expected/actual details are present but no concrete repro code in the issue (only a fork reference)
    Area Area\Connection Pooling (also touches Managed SNI / TLS handshake)
    Duplicates Potentially related: #4642
    Regression Not indicated

    Analysis

    A TCP connection that silently stalls (no FIN/RST) during the TLS handshake never times out, because the handshake and the underlying stream ignore ConnectTimeout. Because the pool opens connections serially, one stuck open blocks all pool growth. The likely affected components are the SNI TLS handshake path (managed SNI SSL stream) and pool connection creation. Severity looks like P1/P2: indefinite hang and pool starvation, but it requires a network failure mode.

    Next Steps

    • @LukeButters, please provide: SqlClient version/commit, .NET target framework, SQL Server version, operating system, and the repro code inline (or a link to the fork tests) so we can proceed with investigation.
    • Maintainers: review Enable UseOverallConnectTimeoutForPoolWait by default in 8.0 #4642 for related timeout behavior.
    • Once the environment is complete, assign to Copilot coding agent to investigate applying the remaining connect-timeout budget (or a cancellation token) to the TLS handshake and stream reads/writes in the SNI SSL layer, so a stalled handshake throws a timeout and the pool can recover.

    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 #4834 · copilot · auto · 22.2 AIC · ⌖ 11.5 AIC · ⊞ 13.5K · ◷

  4. added
    Area\ConnectivityUse this to tag issues that are related to connectivity APIs.
    on Oct 13, 2026
  5. mdaigle commented on Oct 13, 2026

    @mdaigle
    Contributor

    Hey @LukeButters, thanks for the report. Sending the appropriate cancellation token all the way down the stack like you've done in your repro looks like it will be the right approach. I can pick this up as part of #3459, or if you want to tackle this yourself, please do go ahead.

    I also want to call your attention to some related app context switches. These will improve other symptoms that your report mentioned: UseConnectionPoolV2 and UseOverallConnectTimeoutForPoolWait. Pool V2 will let you create connections within the same pool in parallel. UseOverallConnectTimeoutForPoolWait will count time spent waiting in the pool against the connect timeout.

  6. moved this from To triage to Backlog in SqlClient Boardon Oct 13, 2026
  7. self-assigned this
    on Oct 13, 2026
  8. moved this from Backlog to In progress in SqlClient Boardon Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area\ConnectivityUse this to tag issues that are related to connectivity APIs.

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions