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

Make AsyncState thread safe #4833

Merged
merged 5 commits into from
Dec 22, 2023
Merged

Conversation

mobratil
Copy link
Contributor

@mobratil mobratil commented Dec 22, 2023

AsyncState uses holder object AsyncStateHolder that uses List<object?> collection. Write operations to that collection are not thread safe including EnsureCapacity() method. If the async flow is shared between multiple threads the List<> and AsyncState is modified in parallel the list might lose some data.

The fix replaces List<object?> with custom Features class that encapsulates List<object?> collection and synchronizes when its size needs to be expanded.

Microsoft Reviewers: Open in CodeFlow

@mobratil mobratil linked an issue Dec 22, 2023 that may be closed by this pull request
@ghost ghost assigned mobratil Dec 22, 2023
@geeknoid geeknoid merged commit 78a1df9 into main Dec 22, 2023
6 checks passed
@geeknoid geeknoid deleted the 4623-thread-safety-of-iasynccontextt branch December 22, 2023 15:08
@ghost ghost added this to the 8.1 milestone Dec 22, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Thread safety of IAsyncContext<T>
2 participants