Skip to content

Preserve the original exception when SqlDataReader teardown also times out #4638

Description

@mdaigle

Describe the bug

When a per-row transform throws while processing a result set, reader teardown can subsequently time out while draining the remaining rows. The teardown exception, ending in Win32Exception (258): Unknown error 258, replaces the original transform exception entirely. The caller cannot determine why row processing failed.

This variant was confirmed in the Cause B analysis on #1530. The follow-up comment proposes surfacing both exceptions through an AggregateException.

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 teardown timeout replaces the exception thrown by the per-row transform.

To reproduce

  1. Execute a query that returns enough rows that draining them exceeds a short CommandTimeout.
  2. Throw an exception from a per-row transform before the result set is consumed.
  3. Close the reader during exception cleanup.
  4. Observe that the close-time timeout replaces the transform exception.

The linked analysis reports a deterministic reproduction.

Expected behavior

Preserve and surface both the original row-processing exception and the reader teardown exception, for example through an AggregateException.

Further technical details

Microsoft.Data.SqlClient version: Reproduced with the stacks covered by the linked Cause B analysis
.NET target: Sync and async reader teardown paths are relevant
SQL Server version: Reproduced with SQL Server in Docker
Operating system: Linux

Additional context

This issue tracks exception preservation separately from improving the opaque Cause B timeout message. Parent issue: #1530.

Activity

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

    🐛 Bug!Area\Managed SNIIssues that are targeted to the Managed SNI codebase.

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions