Skip to content

Commit b6bba8d

Browse files
committed
Try thread dumping.
1 parent c6213ff commit b6bba8d

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

deploy/tasks/buildah-oci-ta.yaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,18 +398,6 @@ spec:
398398
BUILDAH_ARGS=()
399399
use_domain_proxy=false
400400
401-
cat >> /app/capture-netstat.sh << EOF
402-
#!/bin/bash
403-
while true; do
404-
date >> /app/netstat-output.txt
405-
netstat -a >> /app/netstat-output.txt
406-
echo "--------------------------------------" >> /app/netstat-output.txt
407-
done
408-
EOF
409-
410-
chmod +x /app/capture-netstat.sh
411-
nohup /app/capture-netstat.sh &
412-
413401
if [ "${HERMETIC}" == "true" ]; then
414402
BUILDAH_ARGS+=("--pull=never")
415403
UNSHARE_ARGS="--net"
@@ -564,7 +552,7 @@ spec:
564552
-f "$dockerfile_copy" -t "$IMAGE" .
565553
fi
566554
567-
cat /app/netstat-output.txt
555+
cat /app/thread_dump_*
568556
569557
container=$(buildah from --pull-never "$IMAGE")
570558
buildah mount $container | tee /shared/container_path

java-components/domain-proxy/client/src/main/java/com/redhat/hacbs/domainproxy/client/DomainProxyClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.concurrent.ExecutorService;
1818
import java.util.concurrent.Executors;
1919

20+
import com.redhat.hacbs.domainproxy.common.CommonIOUtil;
2021
import jakarta.annotation.PostConstruct;
2122
import jakarta.annotation.PreDestroy;
2223
import jakarta.inject.Inject;
@@ -75,11 +76,13 @@ private void startClient() {
7576
.open(UnixDomainSocketAddress.of(domainSocket));
7677
executor.submit(channelToChannelBiDirectionalHandler(byteBufferSize, httpClientChannel,
7778
domainSocketChannel));
79+
Thread.sleep(TIMEOUT_MS); // Make sure virtual thread is running
80+
CommonIOUtil.threadDump();
7881
}
7982
}
8083
}
8184
}
82-
} catch (final IOException e) {
85+
} catch (final IOException | InterruptedException e) {
8386
Log.errorf(e, "Error initialising domain proxy client");
8487
}
8588
Quarkus.asyncExit();

java-components/domain-proxy/common/src/main/java/com/redhat/hacbs/domainproxy/common/CommonIOUtil.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

33
import static java.lang.Thread.currentThread;
44

5+
import java.io.FileWriter;
56
import java.io.IOException;
7+
import java.io.PrintWriter;
8+
import java.lang.management.ManagementFactory;
9+
import java.lang.management.ThreadInfo;
10+
import java.lang.management.ThreadMXBean;
611
import java.nio.ByteBuffer;
712
import java.nio.channels.SelectionKey;
813
import java.nio.channels.Selector;
914
import java.nio.channels.SocketChannel;
15+
import java.text.SimpleDateFormat;
16+
import java.util.Date;
1017
import java.util.Iterator;
1118

1219
import org.jboss.logging.Logger;
@@ -160,4 +167,33 @@ private static String getChannelName(final SocketChannel channel) {
160167
}
161168
return channelName;
162169
}
170+
171+
public static void threadDump() throws IOException {
172+
// Create a timestamp with milliseconds for the file name
173+
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS").format(new Date());
174+
String fileName = "/app/thread_dump_" + timestamp + ".txt";
175+
176+
// Create a PrintWriter to write the thread dump to a file
177+
try (PrintWriter writer = new PrintWriter(new FileWriter(fileName))) {
178+
// Get the ThreadMXBean instance
179+
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
180+
181+
// Get all thread IDs
182+
long[] threadIds = threadMXBean.getAllThreadIds();
183+
ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
184+
185+
// Write the thread information to the file
186+
for (ThreadInfo threadInfo : threadInfos) {
187+
writer.println("Thread ID: " + threadInfo.getThreadId() + " Name: " + threadInfo.getThreadName());
188+
writer.println("Thread State: " + threadInfo.getThreadState());
189+
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
190+
for (StackTraceElement stackTraceElement : stackTrace) {
191+
writer.println("\t" + stackTraceElement);
192+
}
193+
writer.println();
194+
}
195+
}
196+
197+
LOG.infof("Thread dump written to file: %s", fileName);
198+
}
163199
}

java-components/domain-proxy/server/src/main/java/com/redhat/hacbs/domainproxy/server/DomainProxyServer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.concurrent.ExecutorService;
2020
import java.util.concurrent.Executors;
2121

22+
import com.redhat.hacbs.domainproxy.common.CommonIOUtil;
2223
import jakarta.annotation.PostConstruct;
2324
import jakarta.annotation.PreDestroy;
2425
import jakarta.inject.Inject;
@@ -75,11 +76,13 @@ private void startServer() {
7576
.open(new InetSocketAddress(LOCALHOST, httpServerPort));
7677
executor.submit(channelToChannelBiDirectionalHandler(byteBufferSize, httpServerChannel,
7778
domainSocketChannel));
79+
Thread.sleep(TIMEOUT_MS); // Make sure virtual thread is running
80+
CommonIOUtil.threadDump();
7881
}
7982
}
8083
}
8184
}
82-
} catch (final IOException e) {
85+
} catch (final IOException | InterruptedException e) {
8386
Log.errorf(e, "Error initialising domain proxy server");
8487
}
8588
Quarkus.asyncExit();

0 commit comments

Comments
 (0)