Play+slick+mysql exception

Tried the google group but it seems it is deprecated. I am trying to connect to a mysql DB from my play/slick application. Whenever, I hit a REST endpoint that tries to read from DB, I get the following:

play.api.UnexpectedException: Unexpected exception[SQLTransientConnectionException: db - Connection is not available, request timed out after 1005ms.]^M
        at play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:186)^M
        at play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:124)^M
        at play.core.server.netty.PlayRequestHandler.handle(PlayRequestHandler.scala:82)^M
        at play.core.server.netty.PlayRequestHandler.channelRead(PlayRequestHandler.scala:185)^M
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)^M
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)^M
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)^M
        at com.typesafe.netty.http.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:129)^M
        at com.typesafe.netty.http.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:96)^M
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)^M
Caused by: java.sql.SQLTransientConnectionException: db - Connection is not available, request timed out after 1005ms.^M
        at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:548)^M
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:186)^M
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:145)^M
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:83)^M
        at slick.jdbc.hikaricp.HikariCPJdbcDataSource.createConnection(HikariCPJdbcDataSource.scala:18)^M
        at play.api.db.slick.evolutions.internal.DBApiAdapter$DatabaseAdapter.getConnection(DBApiAdapter.scala:57)^M
        at play.api.db.slick.evolutions.internal.DBApiAdapter$DatabaseAdapter.getConnection(DBApiAdapter.scala:60)^M
        at play.api.db.evolutions.DatabaseEvolutions.databaseEvolutions(EvolutionsApi.scala:132)^M
        at play.api.db.evolutions.DatabaseEvolutions.scripts(EvolutionsApi.scala:110)^M
        at play.api.db.evolutions.DatabaseEvolutions.scripts(EvolutionsApi.scala:125)^M

I am able to connect to the mysql server mysql workbench.

My application conf looks like this:

db {
  # You can declare as many datasources as you want.
  # By convention, the default datasource is named `default`

  # https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database
  default.driver = org.h2.Driver
  default.url = "jdbc:h2:mem:play;DB_CLOSE_DELAY=-1"
  #default.username = sa
  #default.password = ""
  # You can turn on SQL logging for any datasource
  # https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements
  #default.logSql=true
}
slick.dbs.default.driver = "slick.driver.MySQLDriver$"
slick.dbs.default.db.driver = "com.mysql.jdbc.Driver"
slick.dbs.default.db.url = "jdbc:mysql://x.x.x.x:1725/verifyServerCertificate=false&useSSL=true"

# DB credentials
include file("/xxxx/secrets.properties") #has user and password
slick.dbs.default.db.user = ${user}
slick.dbs.default.db.password = ${password}

Hi,

Can you confirm the database is accessible from the machine where the application is running? It looks like it is not accessible at all instead of having a problem with credentials.

Thanks…it turns out that a max connection limit imposed by the DB was the culprit. But due to the multiple layers of indirection between the application code and the code connecting to the DB (slick->play->hikaricp) it was hard to figure that out.

1 Like

Yes it can be confusing. Glad you got it worked out.