Improve leak logging

pull/294/head
Brett Wooldridge 10 years ago
parent 718b9b5c9d
commit 46b7589026

@ -212,7 +212,7 @@ public abstract class BaseHikariPool implements HikariPoolMBean, IBagStateListen
else {
metricsContext.setConnectionLastOpen(bagEntry, now);
metricsContext.stop();
return ProxyFactory.getProxyConnection((HikariPool) this, bagEntry, leakTask.start());
return ProxyFactory.getProxyConnection((HikariPool) this, bagEntry, leakTask.start(bagEntry.connection));
}
}
while (timeout > 0L);

@ -106,10 +106,10 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
boolean isForceClose = sqlState.startsWith("08") | SQL_ERRORS.contains(sqlState);
if (isForceClose) {
bagEntry.evicted = true;
LOGGER.warn(String.format("Connection %s (%s) marked as broken because of SQLSTATE(%s), ErrorCode(%d).", delegate.toString(),
parentPool.toString(), sqlState, sqle.getErrorCode()), sqle);
LOGGER.warn("Connection {} ({}) marked as broken because of SQLSTATE({}), ErrorCode({}).", delegate.toString(),
parentPool.toString(), sqlState, sqle.getErrorCode(), sqle);
}
else if (sqle.getNextException() instanceof SQLException && sqle != sqle.getNextException()) {
else if (sqle.getNextException() != null && sqle != sqle.getNextException()) {
checkException(sqle.getNextException());
}
}

@ -16,6 +16,7 @@
package com.zaxxer.hikari.util;
import java.sql.Connection;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@ -37,6 +38,7 @@ public class LeakTask implements Runnable
private ScheduledExecutorService executorService;
private long leakDetectionThreshold;
private ScheduledFuture<?> scheduledFuture;
private Connection connection;
private Exception exception;
static
@ -46,7 +48,7 @@ public class LeakTask implements Runnable
public void cancel() {};
@Override
public LeakTask start()
public LeakTask start(final Connection connection)
{
return this;
}
@ -63,15 +65,16 @@ public class LeakTask implements Runnable
{
}
private LeakTask(final LeakTask parent)
private LeakTask(final LeakTask parent, final Connection connection)
{
exception = new Exception("Apparent connection leak detected");
this.exception = new Exception("Apparent connection leak detected");
this.connection = connection;
scheduledFuture = parent.executorService.schedule(this, parent.leakDetectionThreshold, TimeUnit.MILLISECONDS);
}
public LeakTask start()
public LeakTask start(final Connection connection)
{
return new LeakTask(this);
return new LeakTask(this, connection);
}
/** {@inheritDoc} */
@ -83,7 +86,7 @@ public class LeakTask implements Runnable
System.arraycopy(stackTrace, 3, trace, 0, trace.length);
exception.setStackTrace(trace);
LOGGER.warn("Connection leak detection triggered, stack trace follows", exception);
LOGGER.warn("Connection leak detection triggered for connection {}, stack trace follows", connection.toString(), exception);
}
public void cancel()

Loading…
Cancel
Save