3

I'm facing a great problem in connecting to a Postgres database using https://github.com/impossibl/pgjdbc-ng/. I need this lib because I need to get asynchronous notification from the database.

I'm trying to connect to a remote database using SSL an I'm doing this:

Class.forName("com.impossibl.postgres.jdbc.PGDriver");

String url = "jdbc:pgsql://host:5432/db"
                        + "?ssl.mode=Require";
Connection conn = DriverManager.getConnection(url, "username", "pwd");

But, when I try to do that I get an IllegalStateException. This is the stack trace:

java.sql.SQLException: Connection Error: java.lang.IllegalStateException
 at com.impossibl.postgres.jdbc.ConnectionUtil.createConnection(ConnectionUtil.java:189)
 at com.impossibl.postgres.jdbc.PGDriver.connect(PGDriver.java:77)
 at com.impossibl.postgres.jdbc.PGDriver.connect(PGDriver.java:52)
 at java.sql.DriverManager.getConnection(DriverManager.java:179)
 at it.polito.mobile.testpostgres.MainActivity$1.doInBackground(MainActivity.java:60)
 at it.polito.mobile.testpostgres.MainActivity$1.doInBackground(MainActivity.java:35)
 at android.os.AsyncTask$2.call(AsyncTask.java:288)
 at java.util.concurrent.FutureTask.run(FutureTask.java:237)
 at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
 at java.lang.Thread.run(Thread.java:818)
 Caused by: java.io.IOException: java.lang.IllegalStateException
 at com.impossibl.postgres.protocol.v30.ProtocolFactoryImpl.translateConnectionException(ProtocolFactoryImpl.java:285)
 at com.impossibl.postgres.protocol.v30.ProtocolFactoryImpl.connect(ProtocolFactoryImpl.java:199)
 at com.impossibl.postgres.protocol.v30.ProtocolFactoryImpl.connect(ProtocolFactoryImpl.java:90)
 at com.impossibl.postgres.system.BasicContext.<init>(BasicContext.java:130)
 at com.impossibl.postgres.jdbc.PGConnectionImpl.<init>(PGConnectionImpl.java:185)
 at com.impossibl.postgres.jdbc.ConnectionUtil.createConnection(ConnectionUtil.java:180)
 ... 11 more
 Caused by: java.lang.IllegalStateException
 at io.netty.handler.ssl.SslHandler$LazyChannelPromise.executor(SslHandler.java:1491)
 at io.netty.util.concurrent.DefaultPromise.checkDeadLock(DefaultPromise.java:388)
 at io.netty.util.concurrent.DefaultPromise.awaitUninterruptibly(DefaultPromise.java:283)
 at io.netty.util.concurrent.DefaultPromise.syncUninterruptibly(DefaultPromise.java:225)
 at io.netty.util.concurrent.DefaultPromise.syncUninterruptibly(DefaultPromise.java:32)
 at com.impossibl.postgres.protocol.v30.ProtocolFactoryImpl.connect(ProtocolFactoryImpl.java:132)
 ... 15 more

Before, I was using the standard library org.postgresql.Driver and everything worked fine...

Does anybody know how to help me?

Thank you so much! Marco

mgaido
  • 2,987
  • 3
  • 17
  • 39
  • This looks like a bug in the driver. That said, `ssl.mode=Require` is potentially insecure (it doesn't verify the cert), what you'd want is `ssl.mode=VerifyFull`. – Bruno May 31 '15 at 16:18
  • I just ran into the exact same issue - ever find a fix? – brcolow Aug 05 '15 at 05:24
  • It's a bug...as far as I know it was a netty (a lib used in this lib) issue and it has been solved in netty but the dependency has to be updated, so once the library for the postgres driver will be updated pointing to the new netty version, this issue should be solved... – mgaido Aug 07 '15 at 08:42

0 Answers0