Skip to content
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

Sync stream serialization not handling IAsyncEnumerable correctly #66687

Closed
Tracked by #63918
eiriktsarpalis opened this issue Mar 15, 2022 · 3 comments · Fixed by #67035
Closed
Tracked by #63918

Sync stream serialization not handling IAsyncEnumerable correctly #66687

eiriktsarpalis opened this issue Mar 15, 2022 · 3 comments · Fixed by #67035
Assignees
Milestone

Comments

@eiriktsarpalis
Copy link
Member

While adding new tests to System.Text.Json I discovered an issue with the handling of IAsyncEnumerable values in the new sync stream serialization APIs. It would seem like IAsyncEnumerableConverter's sync serialization detection logic is not adequate in identifying the new methods: in debug builds this results in a failed debug assertion whereas release builds end up serializing IAE values successfully, since they accidentally perform sync-over-async enumeration of the source enumerable. We should try to fix this, I can see a couple of options here:

  1. Have the converter detect and fail on sync stream serialization methods. Users that rely on the current behavior might regard this as a breaking change.
  2. Double down on the existing (accidental) behavior and use sync-over-sync for the sync stream serialization methods. Should we consider allowing the same behavior for non-stream sync serialization methods?

cc @steveharter @stephentoub

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Mar 15, 2022
@eiriktsarpalis eiriktsarpalis self-assigned this Mar 15, 2022
@ghost
Copy link

ghost commented Mar 15, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.

Issue Details

While adding new tests to System.Text.Json I discovered an issue with the handling of IAsyncEnumerable values in the new sync stream serialization APIs. It would seem like IAsyncEnumerableConverter's sync serialization detection logic is not adequate in identifying the new methods: in debug builds this results in a failed debug assertion whereas release builds end up serializing IAE values successfully, since they accidentally perform sync-over-async enumeration of the source enumerable. We should try to fix this, I can see a couple of options here:

  1. Have the converter detect and fail on sync stream serialization methods. Users that rely on the current behavior might regard this as a breaking change.
  2. Double down on the existing (accidental) behavior and use sync-over-sync for the sync stream serialization methods. Should we consider allowing the same behavior for non-stream sync serialization methods?

cc @steveharter @stephentoub

Author: eiriktsarpalis
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@eiriktsarpalis eiriktsarpalis added bug and removed untriaged New issue has not been triaged by the area owner labels Mar 15, 2022
@eiriktsarpalis eiriktsarpalis added this to the 7.0.0 milestone Mar 15, 2022
@stephentoub
Copy link
Member

Have the converter detect and fail on sync stream serialization methods

Would this be deterministic, i.e. regardless of the async enumerable's contents, whether it's empty or not, whether its operations complete synchronously or not, you'd always get the exception because it'd be based on the shape rather than on the data?

@eiriktsarpalis
Copy link
Member Author

eiriktsarpalis commented Mar 16, 2022

Have the converter detect and fail on sync stream serialization methods

Would this be deterministic, i.e. regardless of the async enumerable's contents, whether it's empty or not, whether its operations complete synchronously or not, you'd always get the exception because it'd be based on the shape rather than on the data?

Good question. For the non-streaming sync serialization methods the converter throws outright (i.e. it's based on the type shape). It's conceivable that we could make it more adaptable but I suspect this might be setting traps for users (e.g. my mocked IAsyncEnumerable responses were passing all unit tests but serialization is crashing when I deploy the app).

eiriktsarpalis added a commit to eiriktsarpalis/runtime that referenced this issue Mar 23, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 23, 2022
eiriktsarpalis added a commit that referenced this issue Mar 24, 2022
…ly (#67035)

* Fix #66687

* enable small buffer async tests for collections
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 24, 2022
radekdoulik pushed a commit to radekdoulik/runtime that referenced this issue Mar 30, 2022
…ly (dotnet#67035)

* Fix dotnet#66687

* enable small buffer async tests for collections
@ghost ghost locked as resolved and limited conversation to collaborators Apr 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants