Fix Vertx cats fs2 streaming deadlock on limited executors - #5470
Open
arimu1 wants to merge 1 commit into
Open
Conversation
Replace unsafeRunSync in mapToReadStream with non-blocking initialization using JVM concurrency primitives and unsafeRunAndForget for the stream fiber. This prevents exhausting the cats-effect compute pool when ZIO (or other runtimes with small fixed thread pools) backs the Dispatcher. Fixes softwaremill#5458
arimu1
force-pushed
the
fix/vertx-cats-streaming-dispatcher-deadlock-5458
branch
from
August 13, 2026 00:59
aa04a75 to
416d48f
Compare
Author
|
CI note: the lone red |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
VertxCatsServerInterpreterstreams response bodies via fs2 while the cats-effectDispatcherruns on a small fixed thread pool (e.g. ZIO with a 2-thread executor).mapToReadStreamto return the Vert.xReadStreamimmediately using JVM concurrency primitives (AtomicReference,CompletableFuture) for pause/resume and handler wiring, and starts the fs2 fiber withunsafeRunAndForgetinstead of blocking viaunsafeRunSync.Fixes #5458
Problem
Parallel streaming responses called
dispatcher.unsafeRunSyncduringasReadStreamsetup. When the dispatcher shares a limited compute pool with request handling (as in the issue repro with ZIO), all pool threads block waiting for effects that need those same threads — freezing the app.Test plan
sbt "vertxServerCats3/Test/testOnly sttp.tapir.server.vertx.cats.streams.Fs2StreamTest"(JDK 17) — all 5 tests passMade with Cursor