Discussion:
[jruby-user] classpath issues
snacktime
2014-10-12 21:00:10 UTC
Permalink
When using jdbc connection pools, reconnects end up using a classloader
that doesn't use any of the existing classloaders that have the driver jar
so they fail.

The only way I have gotten it to work is to set the classpath using a
wildcard entry or explicit entry for the jarfile. Just having the jars in
the start path or lib doesn't work.

So is having OS/shell specific start scripts that set the classpath before
loading jruby the only way to handle this? That appears to be the case but
thought I would ask before converting my gem binaries.

Chris
snacktime
2014-10-12 23:04:46 UTC
Permalink
So the best solution ended up just having my gem binary call itself if no
classpath was set, and set the classpath on that second run.

Chris
Post by snacktime
When using jdbc connection pools, reconnects end up using a classloader
that doesn't use any of the existing classloaders that have the driver jar
so they fail.
The only way I have gotten it to work is to set the classpath using a
wildcard entry or explicit entry for the jarfile. Just having the jars in
the start path or lib doesn't work.
So is having OS/shell specific start scripts that set the classpath before
loading jruby the only way to handle this? That appears to be the case but
thought I would ask before converting my gem binaries.
Chris
christian
2014-10-13 08:47:13 UTC
Permalink
hi, would you tell me a little more what you are doing like: what are all
those existing classloaders that have the driver jar ? are you using JDBC
directly from jruby ?

are you talking about $CLASSPATH variable inside JRuby which is something
different than $CLASSPATH from environment ?!

are you using jruby-complete.jar or rvm/rbenv/chruby installed jruby ?
snacktime
2014-10-13 18:31:08 UTC
Permalink
I'm using rvm but not tied to it, does it mess with jruby's ability to set
the classpath correctly?

By classpath I mean classpath as displayed in
System.getProperty('java.class.path").

All of the jdbc connection pools are setup in java code. I use them from a
mix of ruby/java but the errors always come from the java side connection
pool reconnect logic where they try to get a new connection after idle
timeouts have killed current connections, or where it's expanding the pool,
etc..

Here is the stack trace I get. You can see the pool timing out idle
connections, and then failing to get a new connection because it can't load
the driver.

20:49:24.962 [Hikari Housekeeping Timer (pool HikariPool-0)] DEBUG
com.zaxxer.hikari.pool.HikariPool - Before cleanup pool stats HikariPool-0
(total=10, inUse=0, avail=10, waiting=0)¬
197284 20:49:24.972 [Hikari Housekeeping Timer (pool HikariPool-0)] DEBUG
com.zaxxer.hikari.pool.HikariPool - After cleanup pool stats HikariPool-0
(total=1, inUse=0, avail=1, waiting=0)¬
197285 20:49:24.977 [HikariCP connection filler] DEBUG
com.zaxxer.hikari.pool.HikariPool - Connection attempt to database
HikariPool-0 failed: No suitable driver found for jdbc:postgresql://
127.0.0.1:5432/gamema
197286 java.sql.SQLException: No suitable driver found for
jdbc:postgresql://
127.0.0.1:5432/gamemachine?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&tcpKeepAlive=false&binaryTransfe
197287 » at java.sql.DriverManager.getConnection(DriverManager.java:596)
~[na:1.7.0_65]¬
197288 » at java.sql.DriverManager.getConnection(DriverManager.java:215)
~[na:1.7.0_65]¬
197289 » at
org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:99)
~[postgresql-9.3-1102-jdbc41.jar:na]¬
197290 » at
org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:82)
~[postgresql-9.3-1102-jdbc41.jar:na]¬
197291 » at
com.zaxxer.hikari.pool.HikariPool.addConnection(HikariPool.java:399)
[HikariCP-java6-2.0.1.jar:na]¬
197292 » at
com.zaxxer.hikari.pool.HikariPool.access$400(HikariPool.java:64)
[HikariCP-java6-2.0.1.jar:na]¬
197293 » at
com.zaxxer.hikari.pool.HikariPool$1AddConnection.run(HikariPool.java:316)
[HikariCP-java6-2.0.1.jar:na]¬
197294 » at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
[na:1.7.0_65]¬
197295 » at java.util.concurrent.FutureTask.run(FutureTask.java:262)
[na:1.7.0_65]¬
197296 » at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
[na:1.7.0_65]¬
197297 » at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
[na:1.7.0_65]¬




Chris
Post by christian
hi, would you tell me a little more what you are doing like: what are all
those existing classloaders that have the driver jar ? are you using JDBC
directly from jruby ?
are you talking about $CLASSPATH variable inside JRuby which is something
different than $CLASSPATH from environment ?!
are you using jruby-complete.jar or rvm/rbenv/chruby installed jruby ?
Loading...