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
H2: The object is already closed [90007-197] #34
Comments
Hi, yep there is a problem:
The pool needs to be able to create new connections whenever needed but you provided a singleton connection! It gets closed by the pool and when the pool wants a new one it gets that closed one again. If NonBlockingConnectionPool pool =
Pools.nonBlocking()
.maxPoolSize(Runtime.getRuntime().availableProcessors() * 5)
.connectionProvider(applicationProperties.getDatasource())
.healthCheck(DatabaseType.H2)
.build(); Otherwise make a custom As this has been reported before I might add these things:
|
I'm adding those changes but I have noticed you can do this with current version: NonBlockingConnectionPool pool =
Pools.nonBlocking()
.maxPoolSize(Runtime.getRuntime().availableProcessors() * 5)
.url(url)
.property("user", user)
.property("password", password)
.healthCheck(DatabaseType.H2)
.build(); I'll add |
…), ConnectionPool.from(url, properties), NonBlockingConnectionPool.Builder.user(user) and .password(password) #34
rxjava2-jdbc 0.1-RC42 has been released to Maven Central and you can now do this: NonBlockingConnectionPool pool =
Pools.nonBlocking()
.maxPoolSize(Runtime.getRuntime().availableProcessors() * 5)
.url(applicationProperties.getDatasource().getUrl())
.user(applicationProperties.getDatasource().getUsername())
.password(applicationProperties.getDatasource().getPassword())
.healthCheck(DatabaseType.H2)
.build(); |
Thanks a lot. Perhaps the reason that this issue has come up repeatedly is that the first Google result for "reactive jdbc" is https://medium.com/netifi/spring-webflux-and-rxjava2-jdbc-83a94e71ba04 - that's where I got the connection code from. I have now added a comment on the article referencing this issue. |
Thanks for the report, the library will be a bit stronger because of it. |
Unfortunately, the fix doesn't work. Code is still as above, with your fix appliend. After a certain period of inactivity, I now get org.h2.jdbc.JdbcSQLException: Table "COMMAND" not found; SQL statement: I tried both
and
with the same result. |
This might be a problem peculiar to the in-memory database in that once all connections to that db are closed the database is effectively thrown away. Perhaps set the logging level to DEBUG to establish what the pool is doing? |
I've just had a look at the source of |
You can pass 0 to |
Just out of interest I noticed this in the H2 docs:
|
Once you've got this working I'll add a section to the README about using H2 in-memory. Thanks for persisting with it (so to speak!). |
heh heh heh yes I'm rather persistent. I had tried the DB_CLOSE_DELAY=-1 previously but it didn't help. Now I added it again in combination with your fix and everything works fine. Thanks! |
Beaut! |
I'm trying to use the library with H2 and I'm finding that the connections get closed after a while, resulting in stacktraces like this:
org.h2.jdbc.JdbcSQLException: The object is already closed [90007-197]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.message.DbException.get(DbException.java:144)
at org.h2.jdbc.JdbcConnection.checkClosed(JdbcConnection.java:1523)
at org.h2.jdbc.JdbcConnection.checkClosed(JdbcConnection.java:1502)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:692)
at org.davidmoten.rx.jdbc.pool.internal.PooledConnection.prepareStatement(PooledConnection.java:57)
I have a couple of Repositories with code like this:
Am I doing something wrong?
The text was updated successfully, but these errors were encountered: