Receive this rarely - "Failed to initialize pool: Communications link failure"

Skip to first unread message

Michael K

Jul 6, 2020, 4:05:08 PM7/6/20
to HikariCP
Hi all. I have 3 Java webapps running on 1 Tomcat. Originally each webapp had their own MySQL Connector/J driver in their libraries, but warnings had appeared about possible memory leaks ("The web application [] appears to have started a thread named [mysql-cj-abandoned-connection-cleanup] but has failed to stop it. This is very likely to create a memory leak."). I researched and read that the proper way to do it was to just have one MySQL Connector/J driver for Tomcat that each webapp uses (in Tomcat's lib directory). So I did that. I also set the leak detection threshold.

But now after a server reboot, I saw -
02-Jul-2020 20:31:52.973 SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [webappListener.WebappListener]
com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: 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.

And that webapp was unable to start. I rebooted again before learning the issue and then it worked fine. 

I have also seen this occur with another of the 3 webapps. That was 4 months ago and that instance did not occur after a reboot. So it has happened twice now. The error that time was - 
Stacktrace: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet successfully received from the server was 0 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(

It seems to be a random and rare issue, but it is serious since the webapp can't run. Below is my config on all 3 webapps, pretty basic. I use HikariCP 2.4.13. I will update those since now I see 3.4.5 is current and I do have Java 8, but I'd definitely like to hear any suggestions. It is a rare occurrence and I don't know when it will pop up again so it won't be a great solution to try a change and check if it is fixed. I appreciate any help!!
    public static void initPool() {
        //register driver
        try {
            //get id of this driver, just used for outputting
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            Enumeration<Driver> drivers = DriverManager.getDrivers();
            while (drivers.hasMoreElements()) {
                Driver driver = drivers.nextElement();
                if (driver.getClass().getClassLoader() == cl) {
                    System.out.println("\n"+"Registered MySQL JDBC driver id: "+driver);
        catch (ClassNotFoundException ex) {
        config = new HikariConfig();
        config.addDataSourceProperty("prepStmtCacheSize" , "250");
        config.addDataSourceProperty("prepStmtCacheSqlLimit" , "2048");
        config.addDataSourceProperty("cachePrepStmts" , "true");
        config.addDataSourceProperty("useServerPrepStmts" , "true");
        config.setLeakDetectionThreshold(60 * 1000);
        connectionPool = new HikariDataSource(config);
        System.out.println("Webapp1 database connection pool has been started.");
Reply all
Reply to author
0 new messages