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

Fix race condition in async enum tracker #869

Merged
merged 1 commit into from
Nov 9, 2022
Merged

Conversation

AArnott
Copy link
Member

@AArnott AArnott commented Nov 9, 2022

Calling BufferBlock<T>.Complete() can set its own Completion property to complete asynchronously. If ReceiveAsync() can throw due to completion before its Completion.IsCompleted is set to true, that would repro this problem. I haven't been able to confirm by code inspection or debugger that the BufferBlock could do this, but based on the exception you report, I can come to no other conclusion. Based on the documentation of the API, it appears that it's safe to assume than any InvalidOperationException is thrown only in the case of a completed block though, so to fix this, I will remove the when clause.

Fixes #867

Calling `BufferBlock<T>.Complete()` can set its own `Completion` property to complete asynchronously. If `ReceiveAsync()` can throw due to completion *before* its `Completion.IsCompleted` is set to `true`, that would repro this problem. I haven't been able to confirm by code inspection or debugger that the `BufferBlock` could do this, but based on the exception you report, I can come to no other conclusion. Based on the documentation of the API, it appears that it's safe to assume than any `InvalidOperationException` is thrown only in the case of a completed block though, so to fix this, I will remove the `when` clause.

Fixes microsoft#867
@AArnott AArnott merged commit f6ecd5f into microsoft:main Nov 9, 2022
@AArnott AArnott deleted the fix867 branch November 9, 2022 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IAsyncEnumerable remoter throws InvalidOperationException sporadically
2 participants