Skip to content

Fix Vertx cats fs2 streaming deadlock on limited executors - #5470

Open
arimu1 wants to merge 1 commit into
softwaremill:masterfrom
arimu1:fix/vertx-cats-streaming-dispatcher-deadlock-5458
Open

Fix Vertx cats fs2 streaming deadlock on limited executors#5470
arimu1 wants to merge 1 commit into
softwaremill:masterfrom
arimu1:fix/vertx-cats-streaming-dispatcher-deadlock-5458

Conversation

@arimu1

@arimu1 arimu1 commented Aug 13, 2026

Copy link
Copy Markdown

Summary

  • Fixes a deadlock when VertxCatsServerInterpreter streams response bodies via fs2 while the cats-effect Dispatcher runs on a small fixed thread pool (e.g. ZIO with a 2-thread executor).
  • Refactors mapToReadStream to return the Vert.x ReadStream immediately using JVM concurrency primitives (AtomicReference, CompletableFuture) for pause/resume and handler wiring, and starts the fs2 fiber with unsafeRunAndForget instead of blocking via unsafeRunSync.

Fixes #5458

Problem

Parallel streaming responses called dispatcher.unsafeRunSync during asReadStream setup. 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 pass
  • Existing coverage exercises pause/resume, interruption, and bidirectional read-stream draining

Made with Cursor

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
arimu1 force-pushed the fix/vertx-cats-streaming-dispatcher-deadlock-5458 branch from aa04a75 to 416d48f Compare August 13, 2026 00:59
@arimu1

arimu1 commented Aug 14, 2026

Copy link
Copy Markdown
Author

CI note: the lone red ci (2.13, JVM, 11) job failed resolving org.scala-sbt:sbt:1.12.14 (forbidden from Maven Central / scala-sbt repos) before tests ran — looks like an sbt launcher/infra issue rather than this change. Other matrix cells were green. Happy to re-trigger when sbt 1.12.14 is fetchable again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] vert.x streaming endpoints hang whole application when VertxCatsServerInterpreter is used with ZIO

1 participant