quarkus: Smallrye GraphQL's parallel execution not compatible with Hibernate reactive

Describe the bug

When creating a GraphQL API with data retrieved with Hibernate reactive, I get the following exception:

2023-04-24 21:14:48,145 ERROR [io.sma.graphql] (vert.x-eventloop-thread-1) SRGQL012000: Data Fetching Error: java.lang.IllegalStateException: Illegal pop() with non-matching JdbcValuesSourceProcessingState

Note that this is very similar to the problem in #32790, but I think here it’s caused by the underlying library graphql-java doing data fetching in parallel (@phillip-kruger correct me if I’m wrong).

Expected behavior

I would expect a straightforward GraphQL query to work without having to think too much about Hibernate Reactive Sessions

Actual behavior

An exception is thrown

How to Reproduce?

Here’s a reproducer: https://github.com/eamelink/graphql-and-hibernate-reactive

Output of uname -a or ver

Darwin Eriks-MacBook-Pro.local 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version “17.0.6” 2023-01-17 OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10) OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.0.0.CR2

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.8 (4c87b05d9aedce574290d1acc98575ed5eb6cd39) Maven home: /Users/eamelink/.m2/wrapper/dists/apache-maven-3.8.8-bin/67c30f74/apache-maven-3.8.8 Java version: 17.0.6, vendor: Eclipse Adoptium, runtime: /Users/eamelink/.sdkman/candidates/java/17.0.6-tem Default locale: en_NL, platform encoding: UTF-8 OS name: “mac os x”, version: “13.3.1”, arch: “aarch64”, family: “mac”

Additional information

No response

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 2
  • Comments: 20 (10 by maintainers)

Most upvoted comments

@eamelink Thank you so much for that blog-post, this issue was driving me insane.

Though, in your solution there was a slight issue.

Instead of:

   @Override
    public <T> Uni<T> protect(Uni<T> uni) {
        return acquire().replaceWith(uni).eventually(this::release);
    }

You meant:

    @Override
    public <T> Uni<T> protect(Supplier<Uni<T>> inner) {
        return acquire().flatMap(ignored -> inner.get()).eventually(this::release);
    }

@DavideD Hm, but SessionFactory.withTransaction() does reuse the existing reactive session, or? I don’t see a difference compared to @WithTransaction

Yes, I’m not sure why it works. It might be that it’s just a bit faster and doesn’t cause the issue.