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

Combination of groupBy and mapAsync involving access to the group causes deadlock. #125

Open
voroninp opened this issue Nov 21, 2020 · 2 comments

Comments

@voroninp
Copy link

Description

My code deadlocks when working with AsyncSeq pipeline.

Repro steps

Code example:

[1;2;3] 
|> AsyncSeq.ofSeq 
|> AsyncSeq.groupBy (fun x -> x) 
|> AsyncSeq.mapAsync (fun (key, gr) -> async {
    let! length = AsyncSeq.length gr
    return (key, length)
})
|> AsyncSeq.toBlockingSeq

Expected behavior

No deadlock, or some xml-doc remarks with the warnings of such possibility, if this is by design.

Known workarounds

It looks like I have to eagerly enumerate the sequence, so all groups get resolved

Related information

  • Operating system Win 10
  • .NET Runtime: 5.0.100
@mlaily
Copy link
Contributor

mlaily commented Apr 20, 2021

I wasted an hour on the same problem.

Then, in the span of two minutes, I found this issue and read the groupBy documentation which contains the following warning:

Note that the resulting async sequence has to be processed in parallel (e.g AsyncSeq.mapAsyncParallel) becaused completion of sub-sequences depends on completion of other sub-sequences.

Using ... |> AsyncSeq.mapAsyncParallel instead of ... |> AsyncSeq.mapAsync fixes the dead-lock.

I guess this is by design. It would be nice if it could be easier to diagnose, or somehow possible to avoid the issue entirely, though :)

@dsyme
Copy link
Contributor

dsyme commented Apr 21, 2021

Perhaps putting a warning CompilerMessage attribute on groupBy makes sense. It's too subtle.

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

No branches or pull requests

3 participants