Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch thrown errors in parEvalMap, parEvalMapUnordered #2826

Merged
merged 3 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/fs2/Stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2123,7 +2123,7 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
Deferred[F2, Unit].flatMap { pushed =>
val init = initFork(channel, pushed.complete(()).void)
poll(init).onCancel(releaseAndCheckCompletion).flatMap { send =>
val action = f(el).attempt.flatMap(send) *> pushed.get
val action = F.catchNonFatal(f(el)).flatten.attempt.flatMap(send) *> pushed.get
F.start(stop.get.race(action) *> releaseAndCheckCompletion)
}
}
Expand Down
22 changes: 22 additions & 0 deletions core/shared/src/test/scala/fs2/ParEvalMapSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,26 @@ class ParEvalMapSuite extends Fs2Suite {
(1 to iterations).toList.as(action).sequence_
}
}

group("issue-2825, Stream shouldn't hang after exceptions thrown in") {
test("parEvalMapUnordered") {
Stream
.eval(IO.unit)
.parEvalMapUnordered(Int.MaxValue)(_ => throw new RuntimeException)
.compile
.drain
.attempt
.timeout(2.seconds)
}

test("parEvalMap") {
Stream
.eval(IO.unit)
.parEvalMap(Int.MaxValue)(_ => throw new RuntimeException)
.compile
.drain
.attempt
.timeout(2.seconds)
}
}
}