-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Received "Connection is closed" for the Connection acquired throught ConnectionRunnable #9815
Comments
Thanks a lot for your report. Are you doing anything else that you may have omitted, before or after the code snippet you've shown? Also, how do you setup/configure your |
Notice that such problems where third party libraries like HikariCP are involved, are always a bit tricky to reproduce. Perhaps an MCVE could help here. We have a handy template for this: https://github.com/jOOQ/jOOQ-mcve |
For example, this example here does not allow for reproducing the problem: SQLDialect family = SQLDialect.POSTGRES;
HikariConfig config = new HikariConfig();
HikariDataSource ds;
config.setJdbcUrl( "jdbc:postgresql://localhost:5432/postgres" );
config.setUsername( "postgres" );
config.setPassword( "test" );
config.addDataSourceProperty( "cachePrepStmts" , "true" );
config.addDataSourceProperty( "prepStmtCacheSize" , "250" );
config.addDataSourceProperty( "prepStmtCacheSqlLimit" , "2048" );
ds = new HikariDataSource( config );
DSLContext ctx = DSL.using(ds, family);
System.out.println(ctx.selectOne().fetch());
ctx.connection(connection -> { //ConnectionRunnable
boolean locked = DSL.using(connection).dsl()
.fetchOne("select pg_try_advisory_lock(?)", 1) //acquire postgres 9.6 advisory lock
.get(0, Boolean.class);
}); |
Hey @lukaseder. Sorry for delay, I was trying few more stuff. I am using Vertx with Jooq. I also tried acquiring Not sure, Could be due to queries running on different thread while using Blocking Executor? |
Thanks for the feedback. I'll have a look soon |
Looking into this now, thanks for your patience. I can reproduce the following using Maven:
Unfortunately, it seems that the combination of Vertx, |
Interseting. In try {
ResultSet rs = connection.createStatement().executeQuery("select 1");
rs.next();
System.out.println(rs.getInt(1));
}
catch (SQLException ignore) {
ignore.printStackTrace();
} But I cannot run: try {
ResultSet rs = connection.prepareStatement("select 1").executeQuery();
rs.next();
System.out.println(rs.getInt(1));
}
catch (SQLException ignore) {
ignore.printStackTrace();
} |
Of course, if I debug this code with breakpoints, then it works. I'd say, there's a race condition somewhere in all this asynchronous code, either in Vertx, HikariCP, or the PostgreSQL JDBC driver (I don't see where jOOQ could cause this, but will continue looking)... |
This seems to be a clue:
Adding this line: System.out.println(Thread.currentThread().getId()); To both
I.e. you're using the same connection instance on two separate threads. I'm not sure if this is really a reasonable restriction in HikariCP, but if you remove HikariCP from the equation, e.g. by specifying: // Create a single connection jOOQ DSLContext without connection pool
dslContext = DSL.using("jdbc:postgresql://localhost/mcve", "postgres", "test");
connectionProvider = dslContext.configuration().connectionProvider(); In the Perhaps this can all be prevented by using the following third party integration: https://github.com/jklingsporn/vertx-jooq I hope this helps |
Getting exception
org.jooq.exception.DataAccessException: SQL [select pg_try_advisory_lock(?)]; Connection is closed
for following code (Connection acquired inside a ConnectionRunnable):Exception log for JOOQ version 3.12.1:
Versions:
The text was updated successfully, but these errors were encountered: