next-issue 14.4.15 → 14.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/shared/children.mjs +19 -0
- package/package.json +1 -1
package/dist/shared/children.mjs
CHANGED
|
@@ -3,6 +3,7 @@ const groups = new Set();
|
|
|
3
3
|
const stoppers = new Set();
|
|
4
4
|
const undos = new Set();
|
|
5
5
|
const current = new AsyncLocalStorage();
|
|
6
|
+
const STOP_GRACE_MS = 10_000;
|
|
6
7
|
export function runChildren() {
|
|
7
8
|
return { groups: new Set(), stoppers: new Set(), stopped: false };
|
|
8
9
|
}
|
|
@@ -24,7 +25,25 @@ function stopAll(children, signal) {
|
|
|
24
25
|
}
|
|
25
26
|
export function stopRunChildren(children) {
|
|
26
27
|
children.stopped = true;
|
|
28
|
+
const running = [...children.groups];
|
|
27
29
|
stopAll(children, 'SIGINT');
|
|
30
|
+
escalate(running, ['SIGTERM', 'SIGKILL']);
|
|
31
|
+
}
|
|
32
|
+
function escalate(running, signals) {
|
|
33
|
+
const [signal, ...later] = signals;
|
|
34
|
+
if (signal === undefined || running.length === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
const left = running.filter((pid) => groups.has(pid));
|
|
39
|
+
for (const pid of left) {
|
|
40
|
+
try {
|
|
41
|
+
process.kill(-pid, signal);
|
|
42
|
+
}
|
|
43
|
+
catch { }
|
|
44
|
+
}
|
|
45
|
+
escalate(left, later);
|
|
46
|
+
}, STOP_GRACE_MS).unref();
|
|
28
47
|
}
|
|
29
48
|
export function runStopped() {
|
|
30
49
|
return current.getStore()?.stopped === true;
|