edulify / play-hikaricp.edulify.com

HikariCP Plugin for Playframework 2.2.x and 2.3.x

Home Page:http://edulify.github.io/play-hikaricp.edulify.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid time conversion on IdleMaxAge

julien-lafont opened this issue · comments

There is an error in the idleTimeout method, the config.getMilliseconds("idleMaxAge") is mistakenly multiplied by 1000.

// Good: only the previous maxLife is multiplied by 1000
private def maxLifetime(config: Configuration) = {
    var maxLife = config.getLong("maxConnectionAgeInMinutes").getOrElse(30L)
    maxLife     = config.getLong("maxConnectionAgeInSeconds").getOrElse(maxLife * 60)
    maxLife     = config.getMilliseconds("maxConnectionAge").getOrElse(maxLife * 1000)
    maxLife.toString
}

// Invalid! The idleMaxAge config itself is multiplied by 1000
private def idleTimeout(config: Configuration) = {
  var idleMaxAge = config.getLong("idleMaxAgeInMinutes").getOrElse(10L)
  idleMaxAge     = config.getLong("idleMaxAgeInSeconds").getOrElse(idleMaxAge) * 60
  idleMaxAge     = config.getMilliseconds("idleMaxAge").getOrElse(idleMaxAge) * 1000
  idleMaxAge.toString
} 

By the way, the code will be more readable with the following structure :

val idleMaxAgeMn = config.getLong("maxConnectionAgeInMinutes").getOrElse(30L)
val idleMaxAgeSec = config.getLong("maxConnectionAgeInSeconds").getOrElse(idleMaxAgeMn * 60)
val idleMaxAgeMs = config.getMilliseconds("maxConnectionAge").getOrElse(idleMaxAgeSec * 1000)

Can make a PR if you want.

Hi @StudioDev,

I agree with your points. Please, make the PR and I will merge it.