SSL connection using pgjdbc-ng as Java driver for Postgres - java

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

Related

Software caused connection abort Client receive

I'm making an app in Android studio and I'm getting an IOException which is unpredictable nor have I managed to replicate it.
W/TcpProtocolLayer: Connection to /x.x.x.x:x closed.
W/System.err: java.io.IOException: Software caused connection abort
W/System.err: at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
W/System.err: at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
W/System.err: at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
W/System.err: at sun.nio.ch.IOUtil.read(IOUtil.java:192)
W/System.err: at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:421)
W/System.err: at x.x.protocol.layer.TcpProtocolLayer.receive(TcpProtocolLayer.java:254)
W/System.err: at x.x.protocol.layer.TcpProtocolLayer.receive(TcpProtocolLayer.java:201)
W/System.err: at x.x.protocol.layer.DatagramProtocolLayer.receive(DatagramProtocolLayer.java:133)
W/System.err: at x.x.protocol.ProtocolStack.receive(ProtocolStack.java:190)
W/System.err: at x.x.protocol.Socket.receive(Socket.java:85)
I've been trying to wrap my head around it and I just can't seem to understand why this would happen, for legal reasons I can't show the code where it's happening but I can describe it.
The phone sends a message to a server and the server responds. This part is always successful and never fails. Then the phone waits for the server to send another message for a confirmation, and this is where it the exception happens. It might throw the exception instantly it might throw it after 10 seconds. I should also say that 90% of the time the code works just fine and no exception is thrown and it processes the information just fine. Then the 10% of the unpredictable attempts this happens and breaks the app completely. I've watched out for it not to be a Async Thread error ,and I've concluded it isn't and the Socket is opened at the moment of this happening. If anyone has any answer I'd be happy to hear it because this problem has been haunting me for a month already and I can't fix it

Flink job runs to fail on EMR cluster

i am developing flink application as Kafka source. I have completed all required changes to code, but its falling into following error when run on one emr cluster. Could you guys let me know the workaround if anyone already experienced.
Caused by: org.apache.flink.runtime.concurrent.FutureUtils$RetryException: Could not complete the operation. Number of retries has been exhausted.
at org.apache.flink.runtime.concurrent.FutureUtils.lambda$retryOperationWithDelay$8(FutureUtils.java:302)
at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:774)
at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:750)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488)
at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1990)
at org.apache.flink.runtime.rest.RestClient.lambda$submitRequest$1(RestClient.java:342)
at org.apache.flink.shaded.netty4.io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:500)
at org.apache.flink.shaded.netty4.io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:493)
at org.apache.flink.shaded.netty4.io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:472)
at org.apache.flink.shaded.netty4.io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:413)
at org.apache.flink.shaded.netty4.io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:538)
at org.apache.flink.shaded.netty4.io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:531)
at org.apache.flink.shaded.netty4.io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:111)
at org.apache.flink.shaded.netty4.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:323)
at org.apache.flink.shaded.netty4.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:339)
at org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:685)
at org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:632)
at org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:549)
at org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:511)
at org.apache.flink.shaded.netty4.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918)
at org.apache.flink.shaded.netty4.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at java.lang.Thread.run(Thread.java:750)
Caused by: java.util.concurrent.CompletionException: org.apache.flink.shaded.netty4.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: ip-xxx-xxx-xxx.dqa.capitalone.com/xx.xxx.xxx.xxx:38257
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:957)
at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:940)
... 19 more
Caused by: org.apache.flink.shaded.netty4.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: ip-xxx-xxx-xxx.dqa.capitalone.com/xx.xxx.xxx.xxx:38257
Caused by: java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:716)
at org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327)
at org.apache.flink.shaded.netty4.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:336)
at org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:685)
at org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:632)
at org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:549)
at org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:511)
at org.apache.flink.shaded.netty4.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918)
at org.apache.flink.shaded.netty4.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at java.lang.Thread.run(Thread.java:750)
EMR Cluster-id:
It's failing with a connection failure, trying to talk to ip-xxx-xxx-xxx.dqa.capitalone.com/xx.xxx.xxx.xxx:38257. It seems likely that internal corporate address is not reachable from inside of AWS.

Lose the connection to WildFly after restarting MySQL server

After restarting MySQL loses the WildFly connection. We used 2 versions MySQL, MySQL Ver 14.14 Distrib 5.6.51, for Linux (x86_64) using EditLine wrappe and MySQL Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)
We tried on 2 versions of Wildfly wildfly-10.1.0.Final and wildfly-19.1.0.Final and we used JDBC a database connector version is - 8.0.19
public static Connection getConnection() throws Exception {
LOG.debug("returning new connection");
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xxx?allowPublicKeyRetrieval=true&useSSL=false", "xxxx", "xxxx");
return con;
}
How can we reconnect automatically after restarting MySQL server, what is the best approach?
We're getting error messages
1. 2022-04-08 16:09:36,614 ERROR [xxx.xxx.mysql.MysqlSentSMSDAo] (DefaultQuartzScheduler_Worker-9) No operations allowed after connection closed.: java.sql.SQLNonTransientConnectionException: No operations allowed after connection closed.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:73)
at com.mysql.cj.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:1659)
at com.mysql.cj.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:1575)
at xxx.xxxx.loader.mysql.MysqlSentSMSDAo.selectReplyRecord(MysqlSentSMSDAo.java:85)
at xxx.xxx.loader.schedular.UpdateReplyReport.execute(UpdateReplyReport.java:109)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
Caused by: com.mysql.cj.exceptions.ConnectionIsClosedException: No operations allowed after connection closed.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
at com.mysql.cj.NativeSession.checkClosed(NativeSession.java:1171)
at com.mysql.cj.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:576)
at com.mysql.cj.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:1590)
... 5 more
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
2. The last packet successfully received from the server was 4,742 milliseconds ago. The last packet sent successfully to the server was 4,744 milliseconds ago.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003)
at xxx.xxx.loader.mysql.MysqlSentSMSDAo.getListOfSQLSentSMSEntities(MysqlSentSMSDAo.java:39)
at xxx.xxx.loader.schedular.UpdateBulkReceipts.execute(UpdateBulkReceipts.java:59)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
Add property autoReconnect=true in the connection string, which makes the connection to auto recover. If you are using Wildfly, then better to define data source in standalone.xml, with autoReconnect=true in <connection-url> tag.
.

jdbc db2 SocketTimeoutException on connecting to database

I am trying to connect to a remote db2 database using the db2 jdbc drivers and am getting a sockertimeout error. I have deployed to two different machines and on the second machine I don't get the error. I'm thinking that this could be something to do with a network connection to the box that my db2 database is on.
Can anyone help me with ways that I can try and debug this error. So far the only think I can come up with is to use tracert hostname to compare the number of hops on the box that the connection works and on the one that it does not.
thanks
[11/5/14 14:22:46:537 EST] 0000d296 SystemErr R Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:413)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:274)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:261)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:389)
at java.net.Socket.connect(Socket.java:556)
at com.ibm.db2.jcc.a.y.run(y.java:34)
at java.security.AccessController.doPrivileged(AccessController.java:241)
at com.ibm.db2.jcc.a.xb.a(xb.java:390)
at com.ibm.db2.jcc.a.xb.<init>(xb.java:79)
at com.ibm.db2.jcc.a.a.x(a.java:265)
at com.ibm.db2.jcc.a.b.a(b.java:1781)
at com.ibm.db2.jcc.b.bb.a(bb.java:394)
at com.ibm.db2.jcc.b.bb.<init>(bb.java:354)
at com.ibm.db2.jcc.a.b.<init>(b.java:314)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:572)
at java.sql.DriverManager.getConnection(DriverManager.java:196)
at com.myer.epostools.db.DBUtility.createConnection(DBUtility.java:18)
at com.myer.eposweb.dao.BaseDAO.getConnection(BaseDAO.java:36)

Which mysql timeout do I must modify?

I've set up on my Raspberry Pi a Glassfish server (4) and a MySQL, to launch my webservices for my Android Application.
Everything is okay after a lot of problems !
But one question stay in my mind for me, why every day I'm trying to execute a query with my app, I must restart my glassfish to have a result (I have a 500 Internal Server Error).
I've searched on the net, and I think it's a timeout from MySQL, who close the connection between him and Glassfish, so I want to know what I must doing to solve this problem ?
Thanks by advance !
EDIT
Stack Trace :
example.webservices.exceptions.ServiceException: L'appel au webservice a rencontré une erreur 500 : could not execute query
at example.webservices.accessservice.UserAccessService.isUserExists(UserAccessService.java:52)
at example.androidapp.asynctasks.VerifyUserTask.doInBackground(VerifyUserTask.java:38)
at example.androidapp.asynctasks.VerifyUserTask.doInBackground(VerifyUserTask.java:20)
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:841)

Categories

Resources