typelevel / typelevel/fs2

Exception in spawned stream cancels Stream.never but swallows the exception

Open
#3,469 0 comments 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

Hi, I found an edge case which causes an exception to be swallowed while cancelling the stream.
The following snippet prints () which was pretty unexpected for me. I would have expected the stream to throw the RuntimeException or at least Stream.never to block the stream forever.

import cats.effect.{IO, IOApp}
import fs2.Stream

object Fs2Bug extends IOApp.Simple {
  override def run: IO[Unit] =
    Stream
      .raiseError[IO](new RuntimeException())
      .spawn
      .flatMap(_ => Stream.never[IO])
      .compile
      .resource
      .drain
      .allocated
      .map { case (r, _) => println(r) }
}

I tested this with v3.10.2 and v3.11.0

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

Start by running the supplied Scala reproduction and tracing Stream.spawn, Stream.never, and the compile().resource path involved in cancellation. Investigate how the spawned stream's RuntimeException is handled; done means the documented cancellation behavior is preserved without swallowing the exception, with regression coverage for the reproduction.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.