fs2 icon indicating copy to clipboard operation
fs2 copied to clipboard

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

Open lhns opened this issue 1 year ago • 0 comments

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

lhns avatar Aug 30 '24 10:08 lhns