Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the stacktrace created when connection is aquired during leak detection #1272

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/com/zaxxer/hikari/pool/ProxyConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ void cancelLeakTask()
leakTask.cancel();
}

/**
* Returns the stacktrace location of where the connection was acquired. If leak detection is not endabled, will
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endabled => enabled

* return an empty array.
*
* @return Array containing StackTraceElement generated when connection was acquired
*/
public StackTraceElement[] getStackTrace()
{
return leakTask.getStackTrace();
}

private synchronized <T extends Statement> T trackStatement(final T statement)
{
openStatements.add(statement);
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/zaxxer/hikari/pool/ProxyLeakTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class ProxyLeakTask implements Runnable
private ScheduledFuture<?> scheduledFuture;
private String connectionName;
private Exception exception;
private String threadName;
private String threadName;
private boolean isLeaked;
private static final StackTraceElement[] NO_STACKTRACE = {};

static
{
Expand All @@ -51,6 +52,12 @@ public void run() {}

@Override
public void cancel() {}

@Override
public StackTraceElement[] getStackTrace()
{
return NO_STACKTRACE;
}
};
}

Expand All @@ -70,13 +77,18 @@ void schedule(ScheduledExecutorService executorService, long leakDetectionThresh
scheduledFuture = executorService.schedule(this, leakDetectionThreshold, TimeUnit.MILLISECONDS);
}

public StackTraceElement[] getStackTrace()
{
return exception.getStackTrace();
}

/** {@inheritDoc} */
@Override
public void run()
{
isLeaked = true;

final StackTraceElement[] stackTrace = exception.getStackTrace();
final StackTraceElement[] stackTrace = exception.getStackTrace();
final StackTraceElement[] trace = new StackTraceElement[stackTrace.length - 5];
System.arraycopy(stackTrace, 5, trace, 0, trace.length);

Expand Down