You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve the timeout error when closing an incompletely consumed SqlDataReader #4639
Closing a SqlDataReader before consuming the full result set drains the remaining rows while the command timeout is still armed. If the drain exceeds the timeout on Linux, the caller receives an opaque timeout ending in Win32Exception (258): Unknown error 258.
The behavior is expected, but the error does not explain that the timeout occurred while draining an incompletely consumed result set or suggest canceling the command before closing the reader.
Exception message: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Inner exception: System.ComponentModel.Win32Exception (258): Unknown error 258
Stack trace: The exception is raised from SqlDataReader.Close/CloseAsync while draining the remaining rows.
To reproduce
Execute a query that returns enough rows that draining them exceeds a short CommandTimeout.
Read only the first row.
Call SqlDataReader.Close() or CloseAsync() without first canceling the command.
Observe the timeout with Unknown error 258.
The linked analysis includes results across Microsoft.Data.SqlClient 5.1.5 through 7.1.0-preview2.
Expected behavior
Surface an error that identifies the timeout as occurring while closing and draining an incompletely consumed reader, with guidance to consume the result set or cancel the command before closing it.
Further technical details
Microsoft.Data.SqlClient version: Reproduced from 5.1.5 through 7.1.0-preview2
.NET target: net8.0 and net9.0 assets, tested on .NET 8, .NET 9, and .NET 10
SQL Server version: Reproduced with SQL Server in Docker
Operating system: Linux
Additional context
Explicit Close() and CloseAsync() surface the exception. Dispose() currently swallows the SqlException from Close(). EF Core calls the throwing close paths, while Dapper cancels the command during teardown and avoids this result.
Not indicated — reproduced consistently across Microsoft.Data.SqlClient 5.1.5 through 7.1.0-preview2
Analysis
This issue asks for an improved, more actionable error message when SqlDataReader.Close()/CloseAsync() times out while draining an incompletely consumed result set on Linux (Managed SNI path), rather than surfacing an opaque Win32Exception (258): Unknown error 258. It is a documentation/diagnostics improvement on top of already-understood behavior (Cause B from #1530), not a new functional defect, so it is best classified as a P2 usability/diagnostics enhancement. The fix would likely live in SqlDataReader.Close/CloseAsync and the TDS parser's row-draining path, where the timeout exception is caught/wrapped before being rethrown.
Assign this issue to the Copilot coding agent to investigate SqlDataReader.Close/CloseAsync in src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ and wrap the timeout SqlException/Win32Exception raised during drain with additional context (e.g. a message noting the timeout occurred while closing an incompletely consumed reader, with guidance to consume the result set or cancel the command first), while preserving the original exception as inner exception per Preserve the original exception when SqlDataReader teardown also times out #4638's ask.
Ensure any fix adds unit/manual tests covering both Close() and CloseAsync() paths on the Managed SNI code path, per repository testing guidelines (cover sync and async variants).
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.
Activity
priyankatiwari08 commentedon Sep 17, 2026
/triage
github-actions commentedon Sep 17, 2026
🔍 Triage Summary (on-demand re-triage)
Area\Managed SNIAnalysis
This issue asks for an improved, more actionable error message when
SqlDataReader.Close()/CloseAsync()times out while draining an incompletely consumed result set on Linux (Managed SNI path), rather than surfacing an opaqueWin32Exception (258): Unknown error 258. It is a documentation/diagnostics improvement on top of already-understood behavior (Cause B from #1530), not a new functional defect, so it is best classified as a P2 usability/diagnostics enhancement. The fix would likely live inSqlDataReader.Close/CloseAsyncand the TDS parser's row-draining path, where the timeout exception is caught/wrapped before being rethrown.Next Steps
SqlDataReader.Close/CloseAsyncinsrc/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/and wrap the timeoutSqlException/Win32Exceptionraised during drain with additional context (e.g. a message noting the timeout occurred while closing an incompletely consumed reader, with guidance to consume the result set or cancel the command first), while preserving the original exception as inner exception per Preserve the original exception when SqlDataReader teardown also times out #4638's ask.Close()andCloseAsync()paths on the Managed SNI code path, per repository testing guidelines (cover sync and async variants).