HikariCP
HikariCP copied to clipboard
Suggestion: Connection leak detection improvement
Currently a check is scheduled when a connection is opened, it waits for the timeout on a ScheduledExecutorService. It's usually cancelled. That is not very useful when you have real long-running tasks mixed in with short-running tasks.
Suggestion: Have a single task running every few seconds, to check when was the last activity on a connection.
replace the ProxyConnection
markCommitStateDirty()
function with a markActivity(Exception lastCall)
void markActivity(Exception lastCall) {
this.lastStack = lastCall;
this.lastActivity = System.currentTimeMillis();
// the rest of what markCommitStateDirty did
}
When the checker thread runs it should do something like:
long now = System.currentTimeMillis();
for (ProxyConnection conn : activeConnections) {
if (!conn.leaked && now - conn.lastActivity > leakDetectionThreshold) {
LOGGER.warn("Connection leak detection triggered...");
conn.leaked = true;
}
}
This will make the analysis more useful to learn which was the last call that stalled. Currently we get the first call that created the connection, which isn't all that useful. It also has the benefit that it only considers a connection stale if it hasn't been used in a while.