Skip to content

Stream.merge hangs when one branch is empty + repeat, unresponsive to interruptAfter and IO.cancel #3697

@TalkingFoxMid

Description

@TalkingFoxMid

Description:

When merging two streams where one branch is Stream.empty.repeat (an infinitely repeating empty stream), the resulting stream hangs indefinitely. Neither interruptAfter nor explicit fiber cancellation via IO.cancel can terminate it.

Expected behavior:

The merged stream should complete (or be interruptible) once the non-empty branch is exhausted and the interrupt/cancel signal is received.

Actual behavior:

The stream hangs forever. Both interruptAfter and fiber.cancel have no effect.

The code:

object Main extends IOApp.Simple {

  override def run: IO[Unit] =
    Supervisor.apply[IO].use { s =>
      for {
        fibra <-
          Stream.empty.repeat
            .merge(
              Stream.emits[IO, Int](List(4, 5, 6))
            )
          .interruptAfter(1.seconds)
          .compile
          .drain
          .start
        _ <- IO.sleep(1.seconds)
        _ <- fibra.cancel
      } yield ()
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions