Skip to content

Commit e19860a

Browse files
authored
Create thread dumps for all running JVMs when the build gets cancelled (#13100)
Motivation: When a GitHub Actions build job gets cancelled because of a timeout, it would be useful to have a thread dump for all running JVM processes so that it would be able to find the reason why the build job timed out. Modification: Add an inline composite action that uses bash, jps and jcmd to create thread dumps for all running Java processes. This is referenced in ci-pr.yml workflow's verify-pr job and gets run when the build job is cancelled. This is an example of a thread dump that gets created: https://github.com/lhotari/netty/pull/1/checks#step:7:28 . Result: Easier to debug builds that did timeout.
1 parent d03f3ed commit e19860a

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright 2023 The Netty Project
3+
#
4+
# The Netty Project licenses this file to you under the Apache License,
5+
# version 2.0 (the "License"); you may not use this file except in compliance
6+
# with the License. You may obtain a copy of the License at:
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
# ----------------------------------------------------------------------------
16+
name: thread dump jvms
17+
description: Triggers a thread dump for all running JVMs
18+
runs:
19+
using: composite
20+
steps:
21+
- run: |
22+
if [[ "$OSTYPE" == "linux-gnu"* ]] && command -v sudo &> /dev/null; then
23+
# use jattach so that Java processes in docker containers are also covered
24+
# download jattach
25+
curl -s -L -o /tmp/jattach https://github.com/apangin/jattach/releases/download/v2.1/jattach
26+
if command -v sha256sum &> /dev/null; then
27+
# verify hash of jattach binary
28+
sha256sum -c <(echo "07885fdc782e02e7302c6d190f54c3930afa10a38140365adf54076ec1086a8e /tmp/jattach") || exit 1
29+
fi
30+
chmod +x /tmp/jattach
31+
for java_pid in $(sudo pgrep java); do
32+
echo "----------------------- pid $java_pid -----------------------"
33+
echo "command line: $(sudo cat /proc/$java_pid/cmdline | xargs -0 echo)"
34+
sudo /tmp/jattach $java_pid jcmd VM.command_line || true
35+
sudo /tmp/jattach $java_pid jcmd "Thread.print -l"
36+
sudo /tmp/jattach $java_pid jcmd GC.heap_info || true
37+
done
38+
else
39+
for java_pid in $(jps -q -J-XX:+PerfDisableSharedMem); do
40+
echo "----------------------- pid $java_pid -----------------------"
41+
jcmd $java_pid VM.command_line || true
42+
jcmd $java_pid Thread.print -l
43+
jcmd $java_pid GC.heap_info || true
44+
done
45+
fi
46+
exit 0
47+
shell: bash

.github/workflows/ci-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ jobs:
7373
- name: Checking bom dependency versions
7474
run: ./.github/scripts/check_bom_dependencies.sh
7575

76+
- name: print JVM thread dumps when cancelled
77+
uses: ./.github/actions/thread-dump-jvms
78+
if: cancelled()
79+
7680
- uses: actions/upload-artifact@v2
7781
if: ${{ failure() }}
7882
with:

.github/workflows/ci-pr.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ jobs:
4949
- name: Checking bom dependency versions
5050
run: ./.github/scripts/check_bom_dependencies.sh
5151

52+
- name: print JVM thread dumps when cancelled
53+
uses: ./.github/actions/thread-dump-jvms
54+
if: cancelled()
55+
5256
build-pr-windows:
5357
runs-on: windows-2019
5458
name: windows-x86_64-java11-boringssl
@@ -73,6 +77,10 @@ jobs:
7377
- name: Build project
7478
run: ./mvnw.cmd -B -ntp --file pom.xml clean package -Pboringssl -DskipHttp2Testsuite=true -DskipAutobahnTestsuite=true
7579

80+
- name: print JVM thread dumps when cancelled
81+
uses: ./.github/actions/thread-dump-jvms
82+
if: cancelled()
83+
7684
- name: Upload Test Results
7785
if: always()
7886
uses: actions/upload-artifact@v2
@@ -193,6 +201,10 @@ jobs:
193201
- name: Checking for detected leak
194202
run: ./.github/scripts/check_leak.sh build-leak.output
195203

204+
- name: print JVM thread dumps when cancelled
205+
uses: ./.github/actions/thread-dump-jvms
206+
if: cancelled()
207+
196208
- name: Upload Test Results
197209
if: always()
198210
uses: actions/upload-artifact@v2
@@ -208,4 +220,4 @@ jobs:
208220
**/target/surefire-reports/
209221
**/target/autobahntestsuite-reports/
210222
**/hs_err*.log
211-
**/core.*
223+
**/core.*

0 commit comments

Comments
 (0)