Skip to content

Commit 24fc64e

Browse files
committed
unify timeout codes
1 parent 0b98883 commit 24fc64e

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

lib/java-caller.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ class JavaCaller {
106106
let child;
107107
let timeoutId;
108108
let killedByTimeout = false;
109+
110+
const wasKilledByTimeout = (code, signal) => {
111+
if (!runOptions.timeout) {
112+
return false;
113+
}
114+
if (killedByTimeout) {
115+
return true;
116+
}
117+
if (signal && signal === runOptions.killSignal) {
118+
return true;
119+
}
120+
const signals = os.constants && os.constants.signals ? os.constants.signals : {};
121+
if (typeof runOptions.killSignal === "string" && signals[runOptions.killSignal] && code === 128 + signals[runOptions.killSignal]) {
122+
return true;
123+
}
124+
if (typeof runOptions.killSignal === "number" && code === 128 + runOptions.killSignal) {
125+
return true;
126+
}
127+
return false;
128+
};
109129
const prom = new Promise((resolve) => {
110130
// Spawn java command line
111131
debug(`Java command: ${javaExeToUse} ${javaArgs.join(" ")}`);
@@ -161,7 +181,7 @@ class JavaCaller {
161181
clearTimeout(timeoutId);
162182
}
163183

164-
if (killedByTimeout || (runOptions.timeout && signal === runOptions.killSignal)) {
184+
if (wasKilledByTimeout(code, signal)) {
165185
// Process was terminated because of the timeout, either via our fallback timer or the built-in spawn timeout
166186
this.status = 666;
167187
stderr += `Process timed out with ${runOptions.killSignal} after ${runOptions.timeout}ms.`;

0 commit comments

Comments
 (0)