Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure 2021

Tags:

java

jdbc

tomcat8

I have a production server that uses Tomcat and MySQL. Today all websites, stopped connecting to it's respective database.

When restarting Tomcat, shows that the connection pool cannot be created for all websites/databases. Here's the error log (for one website):

23-Apr-2021 12:18:49.438 INFO [evaluaciones-grupocomidas.com-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor [/opt/tomcat/conf/Catalina/evaluaciones-grupocomidas.com/ROOT.xml]
23-Apr-2021 12:18:49.690 SEVERE [evaluaciones-grupocomidas.com-startStop-1] org.apache.tomcat.jdbc.pool.ConnectionPool.init Unable to create initial connections of pool.
        com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
                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.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
                at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
                at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
                at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
                at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:319)
                at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:212)
                at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:736)
                at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:668)
                at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:483)
                at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154)
                at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)
                at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107)
                at org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:560)
                at org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:244)
                at org.apache.naming.factory.FactoryBase.getObjectInstance(FactoryBase.java:94)
                at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:332)
                at org.apache.naming.NamingContext.lookup(NamingContext.java:839)
                at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
                at org.apache.naming.NamingContext.lookup(NamingContext.java:827)
                at org.apache.naming.NamingContext.lookup(NamingContext.java:173)
                at org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1017)
                at org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:557)
                at org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:253)
                at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
                at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5063)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
                at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:614)
                at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1823)
                at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
                at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
                at java.lang.Thread.run(Thread.java:748)
        Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

And the content of ROOT.xml is:

    <Resource
            name="jdbc/rhwebDB"
            auth="Container"
            type="javax.sql.DataSource"
            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
            testWhileIdle="true"
            testOnBorrow="true"
            testOnReturn="false"
            validationQuery="SELECT 1"
            validationInterval="30000"
            timeBetweenEvictionRunsMillis="30000"
            maxActive="5"
            minIdle="0"
            maxIdle="5"
            maxWait="10000"
            initialSize="2"
            removeAbandonedTimeout="60"
            removeAbandoned="true"
            logAbandoned="true"
            minEvictableIdleTimeMillis="30000"
            username="grupocom_rhuser"
            password="mypwd"
            driverClassName="com.mysql.cj.jdbc.Driver"
            url="jdbc:mysql://127.0.0.1:3306/grupocom_rhweb?serverTimezone=EST5EDT"/>

This problem started today and I'm running out of options. It was working fine for months (or years) maybe.

The JDBC driver is: mysql-connector-java-8.0.16.jar (an it's located under %CATALINA_HOME%/lib/ MySQL version is: 5.7.34

I've already tried removing the "serverTimezone" from the url parameter, using server's IP instead of 127.0.0.1 and other things but it's still not working.

Any help will be really appreciated

UPDATE

I've found on another log file the rest of the excepction, which might be relevant:

        Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
            at sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:171)
            at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:98)
            at sun.security.ssl.TransportContext.kickstart(TransportContext.java:220)
            at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:428)
            at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:316)
            at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188)
            at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
            at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:352)
like image 520
Sergio Avatar asked Jan 30 '26 06:01

Sergio


2 Answers

Adding request parameter enabledTLSProtocols=TLSv1.2 to the connection URL did the trick for me. (e.g. jdbc:mysql://mydb:3306/myschema?enabledTLSProtocols=TLSv1.2)

Check out https://bugs.mysql.com/bug.php?id=103828

like image 118
flojupp Avatar answered Jan 31 '26 19:01

flojupp


I was able to solve this, doing what other post here suggested:

I commented/disabled these lines on the java.security file:

#jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \
#DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
#include jdk.disabled.namedCurves

In my case, java.security file is located in:

./usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre/lib/security/

like image 43
Sergio Avatar answered Jan 31 '26 20:01

Sergio