quarkusio/quarkus · error · IllegalStateException

No current Vertx context found

Error message

No current Vertx context found

What it means

Reactive Panache operations rely on the current Vert.x context to resolve context objects. Panache.vertxContext() throws IllegalStateException when Vertx.currentContext() returns null, i.e. the code is executing outside any Vert.x context.

Source

Thrown at extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/reactive/Panache.java:113

            current.close();
        } finally {
            MongodbPanacheContextLocalsProvider.SESSION_LOCAL.remove(context);
        }
    }

    /**
     *
     * @return the current vertx duplicated context
     * @throws IllegalStateException If no vertx context is found or is not a safe context as mandated by the
     *         {@link VertxContextSafetyToggle}
     */
    private 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");
        }
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Invoke reactive Panache code only within Vert.x-managed contexts (RESTEasy Reactive endpoints, Vert.x routes, Quarkus-managed Uni subscriptions)
  2. Wrap the work in Quarkus-managed reactive execution instead of a custom executor
  3. Switch to the imperative/blocking Panache API if you must run on a plain thread

Example fix

// before (plain thread)
executor.submit(() -> Panache.withSession(() -> entity.persist()));
// after (Quarkus-managed reactive)
Panache.withSession(() -> entity.persist()).await().indefinitely();
Defensive patterns

Strategy: try-catch

Validate before calling

if (io.vertx.core.Vertx.currentContext() == null) {
    throw new IllegalStateException("Reactive Panache requires a Vert.x context");
}

Try / catch

try {
    return Panache.withSession(() -> repo.persist(e)).await().indefinitely();
} catch (IllegalStateException e) {
    if (e.getMessage().contains("No current Vertx context")) throw new IllegalStateException("Call reactive Panache from a Vert.x context", e);
    throw e;
}

Prevention

When it happens

Trigger: Calling reactive Panache helpers (e.g. Panache.withSession/withTransaction) from a thread that is not a Vert.x worker/event-loop thread, such as a plain executor thread or a blocking main thread.

Common situations: Calling reactive APIs from @Blocking methods or scheduled executors; using reactive Panache in tests without a Vert.x context; mixing blocking code with reactive Panache static helpers.

Related errors


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