Skip to content

Commit e1465a5

Browse files
committed
better threaddump
1 parent 1caf52c commit e1465a5

1 file changed

Lines changed: 37 additions & 27 deletions

File tree

.github/workflows/test.yml

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,56 @@ jobs:
2222
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
2323
- name: Build & Test
2424
run: |
25-
# Create a directory for thread dumps
2625
mkdir -p thread-dumps
2726
28-
# Start a background process to take thread dumps every 15 seconds
29-
(
30-
count=1
31-
while true; do
32-
sleep 15
33-
dump_file="thread-dumps/dump-${count}-$(date +%s).txt"
34-
echo "Taking thread dump $count at $(date)" > "$dump_file"
35-
36-
# Find the Java PIDs and save their thread dumps to the file
37-
jps -q | while read -r pid; do
38-
echo "--- Thread dump for PID $pid ---" >> "$dump_file"
39-
jcmd "$pid" Thread.print >> "$dump_file" 2>&1 || true
40-
done
41-
42-
count=$((count+1))
43-
done
44-
) &
45-
DUMP_PID=$!
46-
47-
# Run the actual Gradle build
27+
# Run Gradle in the background and pipe output to a file
4828
./gradlew \
49-
--console=colored \
29+
--console=plain \
5030
:operator:test \
5131
--fail-fast \
52-
-Dquarkus.test.profile=test-pg${{ matrix.postgres-version }}
32+
-Dquarkus.test.profile=test-pg${{ matrix.postgres-version }} > gradle-output.log 2>&1 &
33+
GRADLE_PID=$!
5334
54-
# Kill the background thread dump process once the build finishes successfully
55-
kill $DUMP_PID || true
35+
# Background watcher: tail the log and look for the exception
36+
tail -f gradle-output.log | while read -r line; do
37+
echo "$line" # Print the line to standard output so you still see the CI logs
38+
39+
# Check if the line contains our target exception
40+
if [[ "$line" == *"listSyncAndWatch failed for"* ]]; then
41+
echo "========================================"
42+
echo "Exception detected! Taking thread dumps..."
43+
echo "========================================"
44+
45+
# Take 3 consecutive thread dumps 2 seconds apart to see if threads are moving
46+
for i in 1 2 3; do
47+
jps -q | while read -r pid; do
48+
dump_file="thread-dumps/threaddump-pid${pid}-run${i}.txt"
49+
echo "Taking thread dump $i for PID $pid at $(date)" > "$dump_file"
50+
jcmd "$pid" Thread.print >> "$dump_file" 2>&1 || true
51+
done
52+
sleep 1
53+
done
54+
55+
# We break out of the loop after taking the dumps
56+
break
57+
fi
58+
done &
59+
WATCH_PID=$!
60+
61+
# Wait for the Gradle build to finish
62+
wait $GRADLE_PID || true
63+
64+
# Cleanup watcher
65+
kill $WATCH_PID || true
5666
env:
5767
GITHUB_USER_NAME: ${{ github.actor }}
5868
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5969

6070
- name: Upload Thread Dumps
61-
if: always() # Run this step even if the "Build & Test" step fails
71+
if: always()
6272
uses: actions/upload-artifact@v7
6373
with:
6474
name: thread-dumps-pg${{ matrix.postgres-version }}
65-
path: thread-dumps/
75+
path: thread-dumps/*.txt
6676
retention-days: 7
6777
compression-level: 3

0 commit comments

Comments
 (0)