Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

[release/3.0] Fix driver behavior of sending Attention signal for successful Bulk Copy operation #42618

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2561,7 +2561,7 @@ private void CopyBatchesAsyncContinuedOnError(bool cleanupParser)

if (_stateObj != null)
{
CleanUpStateObjectOnError();
CleanUpStateObject();
}
}
catch (OutOfMemoryException)
Expand All @@ -2584,7 +2584,7 @@ private void CopyBatchesAsyncContinuedOnError(bool cleanupParser)
}

// Cleans the stateobj. Used in a number of places, specially in exceptions.
private void CleanUpStateObjectOnError()
private void CleanUpStateObject(bool isCancelRequested = true)
{
if (_stateObj != null)
{
Expand All @@ -2594,7 +2594,7 @@ private void CleanUpStateObjectOnError()
_stateObj.ResetBuffer();
_stateObj.ResetPacketCounters();
// If _parser is closed, sending attention will raise debug assertion, so we avoid it (but not calling CancelRequest).
if (_parser.State == TdsParserState.OpenNotLoggedIn || _parser.State == TdsParserState.OpenLoggedIn)
if (isCancelRequested && (_parser.State == TdsParserState.OpenNotLoggedIn || _parser.State == TdsParserState.OpenLoggedIn))
{
_stateObj.CancelRequest();
}
Expand Down Expand Up @@ -2655,7 +2655,7 @@ private void WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet int
_localColumnMappings = null;
try
{
CleanUpStateObjectOnError();
CleanUpStateObject();
}
finally
{
Expand All @@ -2671,7 +2671,7 @@ private void WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet int
_localColumnMappings = null;
try
{
CleanUpStateObjectOnError();
CleanUpStateObject(isCancelRequested: false);
}
finally
{
Expand All @@ -2698,11 +2698,11 @@ private void WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet int

try
{
CleanUpStateObjectOnError();
CleanUpStateObject(isCancelRequested: false);
}
catch (Exception cleanupEx)
{
Debug.Fail("Unexpected exception during CleanUpstateObjectOnError (ignored)", cleanupEx.ToString());
Debug.Fail($"Unexpected exception during {nameof(CleanUpStateObject)} (ignored)", cleanupEx.ToString());
}

if (source != null)
Expand All @@ -2717,11 +2717,11 @@ private void WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet int

try
{
CleanUpStateObjectOnError();
CleanUpStateObject();
}
catch (Exception cleanupEx)
{
Debug.Fail("Unexpected exception during CleanUpstateObjectOnError (ignored)", cleanupEx.ToString());
Debug.Fail($"Unexpected exception during {nameof(CleanUpStateObject)} (ignored)", cleanupEx.ToString());
}

if (source != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void Test(string srcConstr, string dstConstr, string dstTable)
DataTestUtility.AssertEqualsWithDescription((long)0, (long)stats["CursorOpens"], "Non-zero CursorOpens value: " + (long)stats["CursorOpens"]);
DataTestUtility.AssertEqualsWithDescription((long)0, (long)stats["IduRows"], "Non-zero IduRows value: " + (long)stats["IduRows"]);

DataTestUtility.AssertEqualsWithDescription((long)4, stats["BuffersReceived"], "Unexpected BuffersReceived value.");
DataTestUtility.AssertEqualsWithDescription((long)3, stats["BuffersReceived"], "Unexpected BuffersReceived value.");
DataTestUtility.AssertEqualsWithDescription((long)3, stats["BuffersSent"], "Unexpected BuffersSent value.");
DataTestUtility.AssertEqualsWithDescription((long)0, stats["IduCount"], "Unexpected IduCount value.");
DataTestUtility.AssertEqualsWithDescription((long)3, stats["SelectCount"], "Unexpected SelectCount value.");
Expand Down