4
votes

Historically we do a full Tomcat stop/restart after deplying an update. We're switching to using Tomcat manager and redeploy new versions of a war files and in some cases also deploying a war file with a version suffix (e.g. mywar.war##1234) using CodeHaus Cargo. While HikariCP has worked smoothly in the past we're now seeing FATAL errors after Maven and Cargo do a deploy/redoploy. The error is:

[FATAL] java.sql.SQLException: HikariDataSource HikariDataSource (HikariPool-1) has been closed.

I've tried adding singleton="true" to the GlobalResources and each JNDI but that didn't solve the issue.

Note: our JNDI datasources are defined in ~tomcat/conf/server.xml in GlobalNamingResources and they are referenced in each war file's context.xml

Here is the JNDI config. Also, what is the correct MySQL wait_timeout value to use? It is currently set to 60 (60 seconds) which is slightly higher than the maxLifetime in our jdbc setings (55000ms or 55 seconds)

    <Resource name="jdbc/global_mysql" auth="Container" 
factory="com.zaxxer.hikari.HikariJNDIFactory"
type="javax.sql.DataSource"
minimumIdle="1" 
singleton="true"
maximumPoolSize="3"
maxLifetime="55000"
connectionTimeout="300000"
driverClassName="com.mysql.cj.jdbc.Driver"
dataSource.implicitCachingEnabled="true" 
dataSource.user="<user>"
dataSource.password="<password>"
dataSource.cachePrepStmts="true"
dataSource.prepStmtCacheSize="250"
dataSource.prepStmtCacheSqlLimit="2048"
dataSource.useServerPrepStmts="true"
dataSource.useLocalSessionState="true"
dataSource.rewriteBatchedStatements="true"
dataSource.cacheResultSetMetadata="true"
dataSource.cacheServerConfiguration="true"
dataSource.elideSetAutoCommits="true"
dataSource.maintainTimeStats="false"
jdbcUrl="jdbc:mysql://<host>:3306/db"
/>
1
I use DBCP pool (not the Hikari one) and I had never seen such errors. I use closeMethod="close" to trigger closing the pool when Tomcat.shuts down It may worth to try remote debugging to catch when and how the pool is being closed. (My guess it that the web application is coded to explicitly close it, e.g. in a ServletContextListener). See cwiki.apache.org/confluence/display/TOMCAT/…Konstantin Kolinko
Can you provide the code base for testing ?Anish B.
Please add the stacktrace of the errorbenbenw

1 Answers

1
votes

Try to remove driverClassName from the server.xml. Here is the documentation

<!-- driverClassName: Class name for the old mm.mysql JDBC driver is
    org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
    Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
    -->

I have the same FATAL errors connection and solved by removing driverClassName. My environment are:

  1. JVM Azul Zulu 11
  2. Tomcat: 7
  3. J/Connector: 5.1
  4. MySQL: 5.7

Hope it helps.