@wrongstack/tools 0.281.3 → 0.282.0

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/exec.js CHANGED
@@ -455,14 +455,34 @@ function redactCommand(cmd) {
455
455
  return result;
456
456
  }
457
457
  var DEFAULT_GRACE_MS = 2e3;
458
- function killWin32Tree(pid) {
458
+ var WIN32_TASKKILL_TIMEOUT_MS = 5e3;
459
+ function killWin32Tree(pid, opts = {}) {
459
460
  try {
460
461
  const child = spawn("taskkill", ["/pid", String(pid), "/T", "/F"], {
461
462
  stdio: "ignore",
462
463
  windowsHide: true
463
464
  });
464
- child.on("error", () => {
465
- });
465
+ let settled = false;
466
+ let timeout;
467
+ const settle = () => {
468
+ if (settled) return;
469
+ settled = true;
470
+ if (timeout) clearTimeout(timeout);
471
+ try {
472
+ opts.onSettled?.();
473
+ } catch {
474
+ }
475
+ };
476
+ child.on("error", settle);
477
+ child.on("close", settle);
478
+ timeout = setTimeout(() => {
479
+ try {
480
+ child.kill();
481
+ } catch {
482
+ }
483
+ settle();
484
+ }, Math.max(1, opts.timeoutMs ?? WIN32_TASKKILL_TIMEOUT_MS));
485
+ timeout.unref?.();
466
486
  child.unref();
467
487
  return true;
468
488
  } catch {
@@ -692,17 +712,18 @@ var ProcessRegistryImpl = class {
692
712
  const isWin2 = os.platform() === "win32";
693
713
  if (isWin2) {
694
714
  const liveRealChild = p.child.exitCode === null && typeof p.child.pid === "number";
695
- if (liveRealChild && killWin32Tree(pid)) {
696
- const fallback = setTimeout(() => {
697
- if (p.child.exitCode === null) {
698
- try {
699
- p.child.kill("SIGKILL");
700
- } catch {
701
- }
715
+ const directFallback = () => {
716
+ if (p.child.exitCode === null) {
717
+ try {
718
+ p.child.kill("SIGKILL");
719
+ } catch {
702
720
  }
703
- }, graceMs);
704
- fallback.unref?.();
705
- } else {
721
+ }
722
+ };
723
+ if (liveRealChild && killWin32Tree(pid, {
724
+ timeoutMs: Math.max(graceMs, WIN32_TASKKILL_TIMEOUT_MS),
725
+ onSettled: directFallback
726
+ })) ; else {
706
727
  try {
707
728
  p.child.kill(force ? "SIGKILL" : "SIGTERM");
708
729
  } catch {