brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
19.66k stars 2.9k forks source link

HikariCP DB pool is closed - Play Framework - Slick Integration #894

Open murphyj opened 7 years ago

murphyj commented 7 years ago

Environment

play-java-jpa_2.11 (HikariCP bundled): 2.5.14,
JDK version     : 1.8.0_111
Database        : MySQL
Driver version  : 5.1.42

After running the application for a while I get the following logs informing me that the DB connection pool has been shutdown:

2017-05-06 06:12:15,010 [INFO] from application in dbKeepAlive - Keeping database connection alive...
2017-05-06 06:32:15,010 [INFO] from application in dbKeepAlive - Keeping database connection alive...
2017-05-06 06:52:15,010 [INFO] from application in dbKeepAlive - Keeping database connection alive...
2017-05-06 06:58:35,894 [INFO] from application in Thread-8 - Application shutdown...
2017-05-06 06:58:36,054 [INFO] from application in Thread-8 - Shutting down connection pool.

I have tried a number of things, such as, changing the version of the drivers, changing the framework version, tweaking the DB connection configuration and also adding a heartbeat in the code to keep the connections alive.

However, nothing has really helped thus far.

I've posted more details in Stack Overflow with a bounty: http://stackoverflow.com/questions/43824849/play-framework-db-connection-pool-shut-down

Does anyone have any ideas because I'm all out of them?!

brettwooldridge commented 7 years ago

Whose messages are those? "dbKeepAlive"? "Shuttting down connection pool"? Those aren't HikariCP messages.

murphyj commented 7 years ago

Hi @brettwooldridge thanks for responding!

"dbKeepAlive" is TimerTask I've written that hooks into PlayFramework to just poll the database. It still runs the "Shutting down connection pool" line even if that code isn't present. It was my attempt to keep the database connection alive by ensuring a DB connection in the pool was in use every 20 minutes. It didn't work.

"Shutting down connection pool" is probably coming from Play Framework or the slick integration. Although I'm having real trouble figuring out where.

murphyj commented 7 years ago

Okay figured out where it's coming from. It's the close method inside HikariCPModule inside the Play Framework itself. I'm using version 2.11-2.5.3

Example snippet:

  override def close(dataSource: DataSource) = {
    Logger.info("Shutting down connection pool.")
    dataSource match {
      case ds: HikariDataSource => ds.close()
      case _ => sys.error("Unable to close data source: not a HikariDataSource")
    }
  }
}
johnou commented 7 years ago

@murphyj I suggested a few things on SO, namely enabling DEBUG logging for "com.zaxxer.hikari" may help further diagnose what's wrong with the database setup / application and to try extending the HikariCPModule class or implementing it yourself with extra debug code in the close method which prints the current stack eg.

  override def close(dataSource: DataSource) = {
    Logger.info("Shutting down connection pool.")
    Thread.dumpStack()
    dataSource match {
      case ds: HikariDataSource => ds.close()
      case _ => sys.error("Unable to close data source: not a HikariDataSource")
    }