Fix enumerator disposal when cancellation outside of serialization occurs.#120150
Merged
eiriktsarpalis merged 4 commits intodotnet:mainfrom Oct 1, 2025
Merged
Fix enumerator disposal when cancellation outside of serialization occurs.#120150eiriktsarpalis merged 4 commits intodotnet:mainfrom
eiriktsarpalis merged 4 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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
Contributor
|
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
jeffhandley
approved these changes
Sep 30, 2025
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStack.cs
Show resolved
Hide resolved
PranavSenthilnathan
approved these changes
Sep 30, 2025
This was referenced Sep 30, 2025
Member
Author
|
/ba-g test failures unrelated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fix #120010.