Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panache Reactive not working with Quarkus GraphQL #21111

Closed
hogmuzzle opened this issue Oct 31, 2021 · 34 comments
Closed

Panache Reactive not working with Quarkus GraphQL #21111

hogmuzzle opened this issue Oct 31, 2021 · 34 comments

Comments

@hogmuzzle
Copy link

Describe the bug

First query works fine. Others throw IllegalStateException: HR000061: Session is currently connecting to database

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

2 Methods in @GraphQLAPI and call them in one query which is common for gql. The first works fine but others fail.

Output of uname -a or ver

5.13.0-20-generic #20-Ubuntu SMP Fri Oct 15 14:21:35 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.12" 2021-07-20

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.3.0.Final

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

3.8.1

Additional information

No response

@hogmuzzle hogmuzzle added the kind/bug Something isn't working label Oct 31, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Oct 31, 2021

@phillip-kruger
Copy link
Member

Hi @hogmuzzle - thanks for this. Do you have a reproducer ?

@gsmet gsmet added the triage/needs-reproducer We are waiting for a reproducer. label Nov 8, 2021
@vnhim
Copy link

vnhim commented Nov 9, 2021

Hello, have the same issue here. (in quarkus 2.4.1.Final)

Just have a test project (all in a reactive way) with the following dependencies :

  • quarkus-smallrye-graphql
  • quarkus-hibernate-reactive-panache
  • quarkus-reactive-pg-client

I set a resource class which calls a PanacheRepository (something like find("id", id).singleResult<MyEntity>())

Then my resource method should return the Uni.

Everything works fine until 5 or 6 requests, then I get :
SRGQL012000: Data Fetching Error: io.smallrye.mutiny.CompositeException: Multiple exceptions caught: [Exception 0] io.vertx.core.impl.NoStackTraceThrowable: Timeout [Exception 1] java.lang.IllegalStateException: HR000061: Session is currently connecting to database

Seems like a connection not released?

Edit: I don't have a proper reproducer for you but I think that your tutorial https://quarkus.io/guides/getting-started-reactive#reactive-panache-entity should do the trick (just replace the RestResource with the GraphQL one)

Edit 2: Actually I have created a reproducer for you : hibernate-reactive-panache-quickstart.zip
Just call http://localhost:8080/graphql with
{ allFilms{ name } }

Hope this help

@phillip-kruger
Copy link
Member

Hi @vnhim , can you please provide a reproducer?

@vnhim
Copy link

vnhim commented Nov 9, 2021

Hi @phillip-kruger, the reproducer is in the zip file on my previous comment (just your hibernate reactive quickstart with a graph ql resource instead of rest)

@phillip-kruger
Copy link
Member

Got it. Thanks, I'll have a look.

@vnhim
Copy link

vnhim commented Nov 12, 2021

Hi @phillip-kruger, any update on this ?

@phillip-kruger
Copy link
Member

Not yet.

@hogmuzzle
Copy link
Author

I simplified my project in order to provide a reproducer but the problem is gone and I can not send the whole project. I decided to use vertx pgclient + jooq sql builder.

@phillip-kruger
Copy link
Member

OK I manage to recreate this issue. I will debug when I start working on #21433

@phillip-kruger
Copy link
Member

phillip-kruger commented Feb 17, 2022

@hogmuzzle @vnhim

I have started investigating this, as part of making sure GraphQL does Uni in a non blocking manner as I thought that was the problem, however, even after I fixed that, so Uni now run on the event loop, this still happens. I also discussed with @cescoffier, but we might need the help of @Sanne .

@Sanne - quick overview. When we create a GraphQL Endpoint that returns a Uni (in this case of a List of Fruit) that it finds using Hibernate reactive, it works for 5 tries and then hangs and timeout. If i manually create the List of fruits it works fine.

In the screencast below you can see the log lile on the left, and the netstat of java processes on the right, that grows (non port 8080) until 5 and then hangs. After it hangs I can still execute the manual fruit request, but never the hibernate one again.

Can you assist ?
timeout

@phillip-kruger
Copy link
Member

@michalszynkiewicz f.y.i

@Sanne
Copy link
Member

Sanne commented Feb 24, 2022

apologies I missed the first notification :)

I'll have a look

@RuggeroDAlo
Copy link
Contributor

RuggeroDAlo commented Feb 24, 2022

@phillip-kruger The number of calls (4 OK, fifth one fails) sounds suspiciously similar to an issue I have with panache in 2.7.1/2.7.2: #23804

2.7.0 seems to be working fine.

@phillip-kruger
Copy link
Member

Thanks @Sanne and @michalszynkiewicz !

@michalszynkiewicz
Copy link
Member

michalszynkiewicz commented Feb 28, 2022

When trying to debug it I see InternalStateAssertions#assertCurrentThreadMatches during the session close

@michalszynkiewicz
Copy link
Member

@phillip-kruger is it normal that the graphql endpoint is executed on the worker thread even though it returns a Uni?

@phillip-kruger
Copy link
Member

No, that is being fixed, but even with that fix , in my local environment, same problem when using it with reactive hibernate

@michalszynkiewicz
Copy link
Member

is it still failing on this assertion then?

@phillip-kruger
Copy link
Member

I am not sure. I'll commit my branch tomorrow then you can check?

@phillip-kruger
Copy link
Member

@michalszynkiewicz - I still have not committed my branch, trying to get it to a working state. I'll ping you once it's ready

@indiealexh
Copy link

Thought I was doing something wrong.
Glad to see this issue is in progress.
If I can help let me know.

@KienDangTran
Copy link

I still have this issue in 2.8.0.Final. Is there anyone know how to workaround

@dawi
Copy link

dawi commented Apr 25, 2022

@phillip-kruger Is there really no workaround available? I am also facing this issue.

@phillip-kruger
Copy link
Member

@Sanne - did you have a chance to look at this?

@phillip-kruger
Copy link
Member

@dawi no workaround a.f.a.i.k

@joedevgee
Copy link

Also seeing the same issue with 2.8.0 using the graphql @Source annotation. As used in the official quarkus graphql documentation but with reactive panache: https://quarkus.io/guides/smallrye-graphql#expanding-the-api

For example, with reactive panache

@Entity
public class SoupOpera extends PanacheEntityBase {
      public String title;
}

@Entity
public class Episode extends PanacheEntityBase {
      public Long soupOperaId;
      public String title
}

@GraphQLApi
public class SoupOperaResource {
    @Query
    @Description("Fetch soup opera by id")
    public Uni<SoupOpera> findSoupOperaById(Long id) {
        return SoupOpera.findById(id)
    }

    public Uni<List<Episode>> episodes(@Source SoupOpera soupOpera) { 
        return SoupOpera.list('soupOperaId', soupOpera.id)
    }
}

Then If I run below graphql query

query findSoupOperaById(id: 1) {
     title
     episodes {
       title
     }
}

Quarkus will fail with below error

java.lang.IllegalStateException: HR000069: Detected use of the reactive Session from a different Thread
than the one which was used to open the reactive Session -
this suggests an invalid integration;
original thread: 'vert.x-eventloop-thread-12' current Thread: 'executor-thread-1'

Also found similar issue here: dvddhln/quarkus-reactive-hibernate-graphql-crud#1

@phillip-kruger
Copy link
Member

phillip-kruger commented May 5, 2022

This should be fixed in the next version. I'll add a test case for this scenario specifically. see #25194

@zbhavyai
Copy link

zbhavyai commented May 7, 2022

@phillip-kruger Still facing the same issue with latest version 2.8.3.Final. A small reproducer is here - https://github.com/zbhavyai/quarkus-graphql-reactive-pool-reproducer.

Will it be fixed in quarkus version 2.10.Final?

Additional details -

uname -a

Linux pop-os 5.17.5-76051705-generic #202204271406~1651504840~22.04~63e51bd SMP PREEMPT Mon May 2 15: x86_64 x86_64 x86_64 GNU/Linux

java -version

openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment Temurin-11.0.15+10 (build 11.0.15+10)
OpenJDK 64-Bit Server VM Temurin-11.0.15+10 (build 11.0.15+10, mixed mode)

mvn --version

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /opt/apache-maven-3.8.5
Java version: 11.0.15, vendor: Eclipse Adoptium, runtime: /opt/jdk-11.0.15+10
Default locale: en_CA, platform encoding: UTF-8
OS name: "linux", version: "5.17.5-76051705-generic", arch: "amd64", family: "unix"

psql --version

psql (PostgreSQL) 14.2 (Ubuntu 14.2-1ubuntu1)

Thank you.

@phillip-kruger
Copy link
Member

Yes, aiming for 2.10

@zbhavyai
Copy link

zbhavyai commented May 7, 2022

What's the expected release date for version 2.10?

@phillip-kruger
Copy link
Member

Not sure yet. Keep your eye on https://github.com/quarkusio/quarkus/wiki/Release-Planning

@phillip-kruger
Copy link
Member

Good news, I just tested this reproducer with snapshot (main branch) and it's working (or at least it goes past 4 requests :))

If anyone here is keen to test, use the main branch (999-SNAPHOT) and let me know if it's not working. CR1 for 2.10 should also be release in a few weeks and should contain the fix.

vokoscreenNG-2022-05-09_21-38-48

/cc @hogmuzzle @vnhim @RuggeroDAlo @indiealexh @KienDangTran @dawi @joedevgee @zbhavyai @michalszynkiewicz @Sanne @cescoffier

@RuggeroDAlo
Copy link
Contributor

RuggeroDAlo commented May 9, 2022

@phillip-kruger I can confirm that is seems to be working even for #23804 with 999-SNAPSHOT, I'm not sure how changes to graphql fixed it but 🥳 , thanks!

I made a mistake when testing, #23804 still seems broken, 4 messages processed with panache and then nothing, pure hibernate is fine

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

No branches or pull requests