Skip to content

Commit

Permalink
fixup! Prevent deadlock when publisher is canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitriho committed Nov 30, 2024
1 parent d9bd035 commit bcb9c48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/fs2/concurrent/Channel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ object Channel {
new Channel[F, A] {

def sendAll: Pipe[F, A, Nothing] = { in =>
(in ++ Stream.exec(close.void))
in.onFinalize(close.void)
.evalMap(send)
.takeWhile(_.isRight)
.drain
Expand Down
15 changes: 15 additions & 0 deletions core/shared/src/test/scala/fs2/concurrent/ChannelSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,19 @@ class ChannelSuite extends Fs2Suite {
racingSendOperations(channel)
}

test("stream should terminate when sendAll is interrupted") {
val program =
Channel
.bounded[IO, Unit](1)
.flatMap { ch =>
val producer =
Stream
.eval(IO.canceled)
.through(ch.sendAll)

ch.stream.concurrently(producer).compile.drain
}

TestControl.executeEmbed(program) // will fail if program is deadlocked
}
}

0 comments on commit bcb9c48

Please sign in to comment.