Repository navigation
SqlConnection.Open raises wrongly "error occurred during the pre-login handshake" due to thread starvation #3118
Description
Activity
This seems related to known design issues with Managed SNI, look at #422 for more detailed discussions. For now, we would recommend tuning up with threadpool size and providing stable conditions to apps running in Unix. In future releases, we hope to see some improvements in this space.
Reacted by David RettenbacherAppContext switch warning (v7.0.0)
Be aware that the
MakeReadAsyncBlockingswitch routes more reads throughReadSniSyncOverAsync— the same code path that fails under thread starvation in this issue. If you haveMakeReadAsyncBlocking=trueset (e.g. to mitigate async overhead from #1562), it may increase the likelihood of hitting this pre-login handshake error under thread pool pressure.// Avoid setting this if you are experiencing thread starvation errors: AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.MakeReadAsyncBlocking", true);
Reacted by Frulfump/triage
🔍 Triage Summary (on-demand re-triage)
Check Result Issue type Bug Environment All required environment details provided for investigation (SqlClient 5.2.2, .NET 8.0, Azure SQL, Ubuntu 24.04) Area Area\Managed SNIDuplicates Potentially related: #422, #2152 Regression Not indicated Analysis
The reporter demonstrates that under severe thread-pool starvation,
SqlConnection.Open()on Linux (Managed SNI path) surfaces a misleadingSqlException— "error occurred during the pre-login handshake (provider: TCP Provider, error: 0 - Success)" — instead of a clearer timeout/starvation-related error. The underlying issue isTdsParserStateObject.ReadSniSyncOverAsync()/ConsumePreLoginHandshakerelying on thread-pool availability during the synchronous login/pre-login sequence; when the pool is starved, the operation fails with an unhelpful, generic error rather than waiting appropriately or raising a diagnosable timeout. This aligns with the previously acknowledged Managed SNI design limitation (#422) and the broader thread-pool starvation problem tracked in #2152. Severity: P2 — not a crash or data-loss issue, but it produces confusing diagnostics and can affect production reliability under load, particularly on Unix/Linux where Managed SNI is used.Next Steps
- Recommend assigning this issue to Copilot coding agent to investigate
TdsParserStateObject.ReadSniSyncOverAsync()andTdsParser.ConsumePreLoginHandshakein the Managed SNI path (src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/), specifically to (1) surface a more diagnosable error/exception when the underlying cause is thread-pool exhaustion rather than an actual SNI failure, and (2) evaluate whether the pre-login handshake read path can avoid depending on ThreadPool queuing for its synchronous-over-async behavior. - Review linked issues Queries with MultipleActiveResultSets=True (MARS) are very slow / time out on Linux #422 (Managed SNI design discussion) and Possible lock contention/thread pool starvation when acquiring access token causing timeout exceptions #2152 (thread-pool starvation during token acquisition) for related root-cause analysis before starting investigation, since a shared fix or mitigation pattern may apply to all three.
- Consider documenting the
MakeReadAsyncBlockingAppContext switch interaction noted in this thread (it routes more reads through the same code path affected here) as a known caveat in the feature docs.
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 #3118 · copilot · auto · 53.2 AIC · ⌖ 13.1 AIC · ⊞ 11.9K · ◷
- Recommend assigning this issue to Copilot coding agent to investigate
- added a parent issue
on Oct 8, 2026
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog
Describe the bug
SqlConnection.Open raises:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake
When the process experiences thread starvation.
To reproduce
Use Azure SQL Database
Expected behavior
It should await long enough until the thread starvation condition disappears, or it should raise a proper exception.
Further technical details
Microsoft.Data.SqlClient version: 5.2.2
.NET target: .Net 8.0
SQL Server version: Azure SQL, Pool
Operating system: Ubuntu 24.04
Additional context
It is hard to reproduce; just thread starvation is not enough. Parameters should be fine-tuned, even
Console.Writemakes sense.Tested on 2 CPU / 8 Gb RAM VM; Azure SQL was in the same Region (Australia East).
The problem is happening here and there in PROD, but nobody usually analyses the correlation with thread starvation.