-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix System.Text.Json IAsyncEnumerator disposal on cancellation #57505
Fix System.Text.Json IAsyncEnumerator disposal on cancellation #57505
Conversation
…Disposable instances are disposed exactly once. Fixes dotnet#57360.
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsAddresses an issue in System.Text.Json IAsyncEnumerable serialization where, in the event of a user-thrown exception, the serializer will attempt to dispose the IAsyncEnumerator instance without making sure that there are no pending This PR changes the IAsyncEnumerable implementation to wait on any pending Fix #57360. cc @davidfowl
|
...libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/tests/Common/CollectionTests/CollectionTests.AsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
…llectionTests.AsyncEnumerable.cs
...libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/tests/Common/CollectionTests/CollectionTests.AsyncEnumerable.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStack.cs
Show resolved
Hide resolved
...libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs
Show resolved
Hide resolved
/azp run runtime-libraries outerloop |
No pipelines are associated with this pull request. |
/azp list |
/azp run runtime-libraries-coreclr outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
Addresses an issue in System.Text.Json IAsyncEnumerable serialization where, in the event of a user-thrown exception, the serializer will attempt to dispose the IAsyncEnumerator instance without making sure that there are no pending
MoveNextAsync()
operations. In the case of compiler-generated IAsyncEnumerables, this can result in aNotSupportedException
being thrown, see #51176. This issue will most typically manifest in cases where the ambient cancellation token has fired, but authors of the serialized IAsyncEnumerable are not passing that cancellation token to nested async operations.This PR changes the IAsyncEnumerable implementation to wait on any pending
MoveNextAsync()
operations even if an exception has been thrown. This should not have any impact on latency provided that users take care to pass the IAsyncEnumerator cancellation token to any underlying dependencies. It also fixes an unrelated issue where in certain exceptional conditions the serializer would try to dispose the IAsyncEnumerator twice.Fix #57360.
cc @davidfowl