Skip to content

Commit 1b34de8

Browse files
Filter fatal exceptions from Task.FromException in async paths
Fatal exceptions (OOM, StackOverflow, ThreadAbort, NullReference, AccessViolation) must not be wrapped in Task.FromException — they should propagate synchronously. Add ADP.IsCatchableExceptionType guards matching the existing pattern used elsewhere in SqlDataReader. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 52ed94b commit 1b34de8

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,10 @@ private Task ReadFromRowSourceAsync(CancellationToken cts)
13601360
{
13611361
if (_isAsyncBulkCopy)
13621362
{
1363+
if (!ADP.IsCatchableExceptionType(ex))
1364+
{
1365+
throw;
1366+
}
13631367
return Task.FromException<bool>(ex);
13641368
}
13651369
else

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDataReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5476,7 +5476,7 @@ private Task<T> InvokeAsyncCall<T>(SqlDataReaderBaseAsyncCallContext<T> context)
54765476
{
54775477
task = context.Execute(null, context);
54785478
}
5479-
catch (Exception ex)
5479+
catch (Exception ex) when (ADP.IsCatchableExceptionType(ex))
54805480
{
54815481
task = Task.FromException<T>(ex);
54825482
}

0 commit comments

Comments
 (0)