This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
Remove IncrementPendingCallback from MARS sync reads #28427
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While looking into the usage of the LongRunning option usage with SqlClient in the issue https://github.com/dotnet/corefx/issues/19836 it seemed that there is a particular order of MARS execution which can result in hangs (for which the LongRunning options was originally introduced)
A hang in MARS is happening still when a sync execution is followed by an async execution this can be easily reproduced if the following two tests are executed one after another.
System.Data.SqlClient.ManualTesting.Tests.CommandCancelTest.TimeoutCancel
System.Data.SqlClient.ManualTesting.Tests.CommandCancelTest.PlainCancelTestAsync
In case of Mars, SqlClient increments the pending counter by one for sync reads, which is then checked in Async operations at https://github.com/dotnet/corefx/blob/master/src/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs#L2742 and the pending Callback is >=2 causing the Task result to not be set at all. This results in a hang while executing a MARS async operation since the Task result or error will never be set.
Incrementing the pending callbacks were always made for Async operations and in case of MARS, SqlClient was incrementing this counter for sync reads as well.
The code review has two commits
We had added the LongRunning option to MARS async Network API calls because the EF tests were hanging. Given that there is a specific pattern in which this hang can be reproed consistently, LongRunning flag on task continuation may not have been solving any problems for us. I need to confirm that by running EF tests by removing LongRunning continuation option.