-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix enumerator disposal when cancellation outside of serialization occurs. #120150
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 enumerator disposal when cancellation outside of serialization occurs. #120150
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where enumerator disposal was not happening correctly when cancellation occurs outside of serialization, specifically addressing issue #120010. The fix ensures proper cleanup of enumerators when serialization is cancelled by external cancellation tokens.
Key changes:
- Added cancellation token parameters to all serialization wrapper methods to support proper cancellation handling
- Fixed disposal logic in WriteStack to prevent double disposal and handle null stack cases
- Added comprehensive regression tests for both sync and async enumerable cancellation scenarios
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
JsonSerializerWrapper.Reflection.cs | Added CancellationToken parameters to all async serialization methods and updated calls to pass tokens through |
JsonSerializerWrapper.SourceGen.cs | Added CancellationToken parameters to source generation wrapper methods |
CollectionTests.cs | Added JsonSerializable attribute for new test type |
StreamingJsonSerializerWrapper.cs | Updated abstract method signatures to include CancellationToken parameters |
PipeJsonSerializerWrapper.cs | Updated abstract method signatures to include CancellationToken parameters |
CollectionTests.Generic.Write.cs | Added regression test for enumerable cancellation with disposal verification |
AsyncEnumerableTests.cs | Added regression test for async enumerable cancellation with disposal verification |
WriteStack.cs | Fixed disposal logic to prevent double disposal and handle edge cases with null stack |
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStack.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStack.cs
Show resolved
Hide resolved
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStack.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStack.cs
Show resolved
Hide resolved
/ba-g test failures unrelated. |
Fix #120010.