microsoft / microsoft/vs-threading
ValueTask misuse analyzers
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 1k
- Forks
- 160
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 28
Description
While reading Understanding the Whys, Whats, and Whens of ValueTask, it occurred to me that it would be nice to have analyzers that warn when something is done with a ValueTask that should not be done:
- Awaiting a ValueTask / ValueTask multiple times. The underlying object may have been recycled already and be in use by another operation. In contrast, a Task / Task will never transition from a complete to incomplete state, so you can await it as many times as you need to, and will always get the same answer every time.
- Awaiting a ValueTask / ValueTask concurrently. The underlying object expects to work with only a single callback from a single consumer at a time, and attempting to await it concurrently could easily introduce race conditions and subtle program errors. It’s also just a more specific case of the above bad operation: “awaiting a ValueTask / ValueTask multiple times.” In contrast, Task / Task do support any number of concurrent awaits.
- Using .GetAwaiter().GetResult() when the operation hasn’t yet completed. The IValueTaskSource / IValueTaskSource implementation need not support blocking until the operation completes, and likely doesn’t, so such an operation is inherently a race condition and is unlikely to behave the way the caller intends. In contrast, Task / Task do enable this, blocking the caller until the task completes.
The above list is from https://devblogs.microsoft.com/dotnet/understanding-the-whys-whats-and-whens-of-valuetask/#valid-consumption-patterns-for-valuetasks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the linked ValueTask guidance and compare its valid consumption patterns with the repository's existing analyzer work. Done means the proposed misuse cases are addressed by analyzers with appropriate diagnostics and verified behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100