Skip to content

Commit

Permalink
Dump thread info before throwing a buffer leak exception
Browse files Browse the repository at this point in the history
Signed-off-by: Flavia Rainone <frainone@redhat.com>
  • Loading branch information
fl4via committed Mar 30, 2023
1 parent 9693ae9 commit 2d6dddc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/test/java/io/undertow/testutils/DefaultServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.URI;
Expand Down Expand Up @@ -101,6 +104,8 @@
import static io.undertow.server.handlers.ResponseCodeHandler.HANDLE_404;
import static io.undertow.testutils.StopServerWithExternalWorkerUtils.stopWorker;
import static io.undertow.testutils.StopServerWithExternalWorkerUtils.waitWorkerRunnableCycle;
import static java.util.Arrays.*;
import static java.util.stream.Collectors.*;
import static org.xnio.Options.SSL_CLIENT_AUTH_MODE;
import static org.xnio.SslClientAuthMode.REQUESTED;

Expand Down Expand Up @@ -399,6 +404,11 @@ public void testFinished(Description description) throws Exception {
throw new RuntimeException(e);
}
if (!empty) {
// dump the threads, if one thread is holding from closing che channel
// after 2 minutes, we need to see what it is doing
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
ThreadInfo[] infos = bean.dumpAllThreads(true, true);
System.out.println(stream(infos).map(Object::toString).collect(joining()));
for (DebuggingSlicePool.DebuggingBuffer b : DebuggingSlicePool.BUFFERS) {
b.getAllocationPoint().printStackTrace();
notifier.fireTestFailure(new Failure(description, new RuntimeException("Buffer Leak " + b.getLabel(), b.getAllocationPoint())));
Expand Down

0 comments on commit 2d6dddc

Please sign in to comment.