Leakage in async computation awaiting for a ValueTask
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
this code
```
let rec streamLoop (enumerator: IAsyncEnumerator<'reply>) = async {
let! hasNext = enumerator.MoveNextAsync()
if hasNext then
try onNewItem enumerator.Current with | _ -> ()
return! streamLoop enumerator }
```
creates a memory leak. Memory in Visual Studio Diagnostic Tools reveal a constantly increasing number of `ContinuationTaskFromResultTask`.
Fix simply adding .AsTask() |> Async.AwaitTask
```
let rec streamLoop (enumerator: IAsyncEnumerator<'reply>) = async {
let! hasNext = enumerator.MoveNextAsync().AsTask() |> Async.AwaitTask
if hasNext then
try onNewItem enumerator.Current with | _ -> ()
return! streamLoop enumerator }
```
Suggests incorrrect interaction of F# Async with ValueTask<> or IAsyncEnumerator<>.MoveNextAsync()
Contributor guide
Assessment
This issue has not been assessed yet.