Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e9e309c

Browse files
authored
Added cleanup for cached async state in SqlCommand's EndExecute methods before they throw exceptions. Without this cleanup, a subsequent command execution will fail since it will appear as though other async commands are still pending. (#20339) (#20373)
1 parent 7b33264 commit e9e309c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,10 @@ private int EndExecuteNonQuery(IAsyncResult asyncResult)
10021002
if (asyncException != null)
10031003
{
10041004
// Leftover exception from the Begin...InternalReadStage
1005+
if (cachedAsyncState != null)
1006+
{
1007+
cachedAsyncState.ResetAsyncState();
1008+
}
10051009
ReliablePutStateObject();
10061010
throw asyncException.InnerException;
10071011
}
@@ -1266,6 +1270,10 @@ private XmlReader EndExecuteXmlReader(IAsyncResult asyncResult)
12661270
if (asyncException != null)
12671271
{
12681272
// Leftover exception from the Begin...InternalReadStage
1273+
if (cachedAsyncState != null)
1274+
{
1275+
cachedAsyncState.ResetAsyncState();
1276+
}
12691277
ReliablePutStateObject();
12701278
throw asyncException.InnerException;
12711279
}
@@ -1396,6 +1404,10 @@ private SqlDataReader EndExecuteReader(IAsyncResult asyncResult)
13961404
if (asyncException != null)
13971405
{
13981406
// Leftover exception from the Begin...InternalReadStage
1407+
if (cachedAsyncState != null)
1408+
{
1409+
cachedAsyncState.ResetAsyncState();
1410+
}
13991411
ReliablePutStateObject();
14001412
throw asyncException.InnerException;
14011413
}

0 commit comments

Comments
 (0)