-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathpost.js
More file actions
40 lines (37 loc) · 1.11 KB
/
post.js
File metadata and controls
40 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const { execSync } = require("child_process");
function run(command) {
execSync(command, { stdio: "inherit", shell: "/bin/bash" });
}
function dumpThreads() {
run('echo "== Cancellation detected: capturing JVM thread dumps =="');
run(
[
"set -euo pipefail",
"pids=$(pgrep -f '[j]ava' || true)",
'if [[ -z "${pids}" ]]; then echo "No Java processes found."; exit 0; fi',
"if command -v jcmd >/dev/null 2>&1; then",
" for pid in ${pids}; do",
' echo "-- jcmd Thread.print for PID ${pid} --"',
" jcmd \"${pid}\" Thread.print || true",
" done",
" exit 0",
"fi",
"if command -v jstack >/dev/null 2>&1; then",
" for pid in ${pids}; do",
' echo "-- jstack for PID ${pid} --"',
" jstack \"${pid}\" || true",
" done",
" exit 0",
"fi",
"for pid in ${pids}; do",
' echo "-- kill -QUIT ${pid} (no jcmd/jstack available) --"',
" kill -QUIT \"${pid}\" || true",
"done",
].join("\n")
);
}
try {
dumpThreads();
} catch (error) {
console.error("Thread dump post-step failed:", error);
}