Stream.merge hangs when one branch is empty + repeat, unresponsive to interruptAfter and IO.cancel
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 2.5k
- Forks
- 636
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 7
Description
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 ()
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Main reproduction and trace Stream.merge together with interruptAfter and IO.cancel. Compare behavior when the empty repeating branch is merged with the finite Stream.emits branch. Done means the merged stream completes or responds to the interruption and cancellation signals instead of hanging indefinitely.
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
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100