quarkusio/quarkus · error · IllegalStateException

No current Vertx context found

Error message

No current Vertx context found

What it means

SessionOperations.vertxContext() returns the current Vert.x context for looking up Hibernate Reactive sessions; it throws IllegalStateException("No current Vertx context found") when Vertx.currentContext() returns null, i.e. the code is running on a non-Vert.x thread (or a thread without a context) where reactive session state cannot be stored or found. Valid contexts are additionally validated with VertxContextSafetyToggle. This is a thread/context mismatch — Panache reactive operations must run on a Vert.x (duplicated) context.

Source

Thrown at extensions/panache/hibernate-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/runtime/SessionOperations.java:384

                .orElse(null);
    }

    private static void trackOnDemandSession(Context context, String persistenceUnitName) {
        Set<String> onDemandSessionsCreated = ContextLocals.get(context, SESSION_ON_DEMAND_OPENED_KEY, null);
        if (onDemandSessionsCreated == null) {
            onDemandSessionsCreated = new HashSet<>();
            ContextLocals.put(context, SESSION_ON_DEMAND_OPENED_KEY, onDemandSessionsCreated);
        }
        onDemandSessionsCreated.add(persistenceUnitName);
    }

    public static Context vertxContext() {
        Context context = Vertx.currentContext();
        if (context != null) {
            VertxContextSafetyToggle.validateContextIfExists(ERROR_MSG, ERROR_MSG);
            return context;
        } else {
            throw new IllegalStateException("No current Vertx context found");
        }
    }

    /**
     * Close any session open for that persistence unit (stateless or managed, there can be only one opened at a time)
     */
    static Uni<Void> closeSession(String persistenceUnitName) {
        LOG.debugf("Closing session for Persistence Unit '%s'", persistenceUnitName);
        Context context = vertxContext();
        return OPENED_SESSIONS_STATE.closeSession(context, persistenceUnitName)
                .chain(() -> OPENED_SESSIONS_STATE_STATELESS.closeSession(context, persistenceUnitName));
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Run the database work on a Vert.x context: use Quarkus-managed entry points (REST, @WithSession/@WithTransaction-annotated methods, Mutiny pipelines started from them).
  2. Avoid @Blocking or thread-hopping around reactive session code; keep the chain within Mutiny and let Quarkus manage execution.
  3. If you must offload, capture the current duplicated context first and re-run the work on it (context.runOnContext / VertxContextSupport).
  4. In tests, use QuarkusTest reactive testing utilities so calls execute within the Vert.x event-loop context.

Example fix

// before
CompletableFuture.runAsync(() -> {
    Person.findById(id); // IllegalStateException: No current Vertx context
});

// after
Uni.createFrom().item(1L)
    .chain(id -> Person.findById(id)) // runs on the Vert.x duplicated context
    .subscribeAsCompletionStage();
Defensive patterns

Strategy: validation

Validate before calling

if (Vertx.currentContext() == null) {
    throw new IllegalStateException("Not on a Vert.x thread; run Panache reactive calls within a Vert.x duplicated context (e.g. from @WithSession-annotated methods)");
}

Try / catch

try { doReactiveDbWork(); } catch (IllegalStateException e) { if (e.getMessage().contains("No current Vertx context")) { log.error("Reactive session code ran off the Vert.x event loop", e); } throw e; }

Prevention

When it happens

Trigger: Invoking Panache reactive APIs from plain Java threads (main, executor pools, CompletableFuture.supplyAsync default pool), blocking dispatches, or any place Vert.x did not establish a current context; also from safe/invalid contexts rejected by the safety toggle path.

Common situations: Running reactive DB calls inside @Blocking methods; scheduling via java.util.Timer/Executors; calling Panache from a gRPC worker thread or servlet-style thread; tests running on the main thread without quarkus-test Vert.x context setup.

Related errors


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