Lesson Learned #509: KeepAliveTime parameter in HikariCP

This post has been republished via RSS; it originally appeared at: Microsoft Tech Community - Latest Blogs - .

Using a network trace, I observed that once the connections are established and to keep them active, the operating system sends a TCP Keep-Alive, which indicates how often it checks that the connection remains active in the HikariCP connection pool.

 

Jose_Manuel_Jurado_0-1727441449080.png

 

In this situation, my first idea for idle connection in the HikariCP pool was to configure KeepAliveTime parameter. HikariCP will send a lightweight query (such as SELECT 1) to idle connections that have been inactive for longer than this parameter value. This keeps the connection alive, avoiding unexpected disconnections by external systems.

 

We could see the results in the following network trace and SQL Profiler. 

 

Jose_Manuel_Jurado_1-1727441716418.png

 

Jose_Manuel_Jurado_2-1727441756434.png

 

Network setups, such as those involving firewalls, have policies that close idle connections after a certain period. If a connection is closed in this way and keepalivetime is not set, HikariCP will only detect the closure when the connection is requested from the pool. 

 

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.