typelevel / typelevel/fs2

parEvalMap and it's variations hang on canceled effect

Open
#3,486 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Scala
Stars
2.5k
Forks
636
Avg merge
2d 4h
Merged PRs (30d)
7

Description

fs2 version 3.10.2

this code does not terminate:

Stream.unit // number of elements is irrelevant, as long as there are any; does not reproduce on Stream.empty
  .covary[IO]
  .parEvalMap(2)(_ => IO.canceled)
  .compile.drain

while there is no issue with evalMap:

Stream.unit
  .covary[IO]
  .evalMap(_ => IO.canceled)
  .compile.drain

even worse, adding interruptAfter after parEvalMap does not make the code terminate:

Stream.unit
  .covary[IO]
  .parEvalMap(2)(_ => IO.canceled)
  .interruptAfter(5.seconds)
  .compile.drain

it is not necessary for all effects to be cancelled, one is enough. This also hangs:

    Stream(IO.unit, IO.canceled)
      .covary[IO]
      .parEvalMap(2)(identity)
      .compile.drain

expected behavior:

while it's not obvious what to hope for in relation to concurrently executing effects - whether they should also cancel or not - one would expect overall termination semantics to be the same across evalMap and parEvalMap. It is also difficult to reason how to work around such situation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the hang with the parEvalMap and compile.drain examples in the issue, then inspect the parEvalMap implementation and its cancellation handling. Compare its behavior with evalMap, including interruptAfter, and add coverage for a canceled effect; done means these examples terminate with consistent cancellation semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
stream-processing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.