Hello. A little followup to Hikari question. It se...
# exposed
r
Hello. A little followup to Hikari question. It seems like I have a connection leak. Sometime when I reload application (Ktor) old connections stays. I do cancel HikariDataSource but the question is: Do I have to cancel something Exposed specific when application closes? Hikari config:
Copy code
val config = HikariConfig().apply {
    jdbcUrl = databaseUrl
    driverClassName = driver.driverClass
    username = user.userName
    password = user.password
    maximumPoolSize = 25
    minimumIdle = 1
    idleTimeout = 1.minutes.inWholeMilliseconds
}
and cleanup:
Copy code
val dataSource = HikariDataSource(config)

application.environment.monitor.subscribe(ApplicationStopping) {
    dataSource.close()
}
s
Not sure its enough but we also close the Database:
Copy code
fun Database.asCloseable() = Closeable {
    TransactionManager.closeAndUnregister(this)
}
Database being a
org.jetbrains.exposed.sql.Database
r
I'll give it a try, thanks! Do you also use Ktor? Is a "ApplicationStopping" event right place to do such a cleanup?
s
Looks like you ought to use ApplicationStopped: https://ktor.io/docs/events.html#predefined-events
r
Oh, I was afraid that "Stopping" was too late but they suggest Stopped. Well I'll try this as well