Jump to content

Lesson Learned #500: Connection Leaks and Query Execution using HikariCP


Recommended Posts

Guest Jose_Manuel_Jurado
Posted

Other lesson learned about HikariCP has been when we enabled setLeakDetectionThreshold working on a service request was receiving the following error message: 20:21:42.089 [AppExample-ConnectionPooling housekeeper] WARN com.zaxxer.hikari.pool.ProxyLeakTask - Connection leak detection triggered for ConnectionID:1 ClientConnectionId: b9b5344d-f970-XXX-xxxxxxxxxx on thread main, stack trace follows java.lang.Exception: Apparent connection leak detected at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:100)

 

 

 

The learned lesson here was, that, in the context of connection leak detection in HikariCP, it is not only the closing of the connection that matters but also the execution of the query and the handling of associated resources. A connection leak occurs when a connection is acquired from the pool but not returned, which can include not properly closing ResultSet and PreparedStatement objects as well as the connection itself. In this case, I found a query that took more than that this setting.

 

[HEADING=2]Considerations for Leak Detection[/HEADING]

 

 

 

[HEADING=3]1. Query Execution:[/HEADING]

  • If a query takes a long time to execute, it can appear as a leak if the execution time exceeds the configured leak detection threshold (leak-detection-threshold).
  • It is important to optimize queries to ensure they complete in a reasonable time frame.

[HEADING=3]2. Closing the Connection:[/HEADING]

  • Ensuring the connection is closed after its use is complete, regardless of whether the query was successful or failed.

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...