quarkusio/quarkus · error · IllegalStateException

No Vertx context found

Error message

No Vertx context found

What it means

prepareExecution is a shared helper that builds the coroutine dispatcher and application scope for Kotlin suspend/Flow endpoints. It captures the CDI request scope and requires an active Vert.x context; otherwise it throws IllegalStateException("No Vertx context found").

Source

Thrown at extensions/resteasy-reactive/rest-kotlin/runtime/src/main/kotlin/org/jboss/resteasy/reactive/server/runtime/kotlin/PrepareExecution.kt:14

package org.jboss.resteasy.reactive.server.runtime.kotlin

import io.vertx.core.Vertx
import jakarta.enterprise.inject.spi.CDI
import kotlinx.coroutines.CoroutineDispatcher
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext

fun prepareExecution(
    requestContext: ResteasyReactiveRequestContext
): Pair<CoroutineDispatcher, ApplicationCoroutineScope> {
    val requestScope = requestContext.captureCDIRequestScope()
    val dispatcher: CoroutineDispatcher =
        Vertx.currentContext()?.let { VertxDispatcher(it, requestScope, requestContext) }
            ?: throw IllegalStateException("No Vertx context found")

    val coroutineScope = CDI.current().select(ApplicationCoroutineScope::class.java)
    requestContext.suspend()

    return Pair(dispatcher, coroutineScope.get())
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Route requests through the normal RESTEasy Reactive HTTP pipeline
  2. Avoid moving request handling to non-Vert.x threads before coroutine preparation
  3. In tests, use the QuarkusTest HTTP client instead of direct method calls
  4. Check extensions that alter threading/dispatch (e.g. custom @RunOnVirtualThread setups)
Defensive patterns

Strategy: try-catch

Validate before calling

require(io.vertx.core.Vertx.currentContext() != null) { "prepareExecution requires an active Vert.x context" }

Type guard

fun prepareExecutionSafe(ctx: ResteasyReactiveRequestContext): Pair<CoroutineDispatcher, ApplicationCoroutineScope>? =
    if (io.vertx.core.Vertx.currentContext() != null) prepareExecution(ctx) else null

Try / catch

try {
    val (dispatcher, scope) = prepareExecution(requestContext)
    // proceed
} catch (e: IllegalStateException) {
    if (e.message?.contains("No Vertx context found") == true) {
        requestContext.handleException(e, true)
    } else throw e
}

Prevention

When it happens

Trigger: suspend or Flow endpoint execution invoked on a thread lacking a Vert.x context, so `Vertx.currentContext()` returns null while building the VertxDispatcher.

Common situations: Direct invocation of suspend endpoints outside the HTTP pipeline; custom executor/threading setups; corrupted dispatch chain where request handling left the Vert.x context.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/8f7e35d47fe2ed70. Report an issue: GitHub.