@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/bash.js CHANGED
@@ -403,14 +403,34 @@ function redactCommand(cmd) {
403
403
  return result;
404
404
  }
405
405
  var DEFAULT_GRACE_MS = 2e3;
406
- function killWin32Tree(pid) {
406
+ var WIN32_TASKKILL_TIMEOUT_MS = 5e3;
407
+ function killWin32Tree(pid, opts = {}) {
407
408
  try {
408
409
  const child = spawn("taskkill", ["/pid", String(pid), "/T", "/F"], {
409
410
  stdio: "ignore",
410
411
  windowsHide: true
411
412
  });
412
- child.on("error", () => {
413
- });
413
+ let settled = false;
414
+ let timeout;
415
+ const settle = () => {
416
+ if (settled) return;
417
+ settled = true;
418
+ if (timeout) clearTimeout(timeout);
419
+ try {
420
+ opts.onSettled?.();
421
+ } catch {
422
+ }
423
+ };
424
+ child.on("error", settle);
425
+ child.on("close", settle);
426
+ timeout = setTimeout(() => {
427
+ try {
428
+ child.kill();
429
+ } catch {
430
+ }
431
+ settle();
432
+ }, Math.max(1, opts.timeoutMs ?? WIN32_TASKKILL_TIMEOUT_MS));
433
+ timeout.unref?.();
414
434
  child.unref();
415
435
  return true;
416
436
  } catch {
@@ -640,17 +660,18 @@ var ProcessRegistryImpl = class {
640
660
  const isWin2 = os2.platform() === "win32";
641
661
  if (isWin2) {
642
662
  const liveRealChild = p.child.exitCode === null && typeof p.child.pid === "number";
643
- if (liveRealChild && killWin32Tree(pid)) {
644
- const fallback = setTimeout(() => {
645
- if (p.child.exitCode === null) {
646
- try {
647
- p.child.kill("SIGKILL");
648
- } catch {
649
- }
663
+ const directFallback = () => {
664
+ if (p.child.exitCode === null) {
665
+ try {
666
+ p.child.kill("SIGKILL");
667
+ } catch {
650
668
  }
651
- }, graceMs);
652
- fallback.unref?.();
653
- } else {
669
+ }
670
+ };
671
+ if (liveRealChild && killWin32Tree(pid, {
672
+ timeoutMs: Math.max(graceMs, WIN32_TASKKILL_TIMEOUT_MS),
673
+ onSettled: directFallback
674
+ })) ; else {
654
675
  try {
655
676
  p.child.kill(force ? "SIGKILL" : "SIGTERM");
656
677
  } catch {
@@ -1710,17 +1731,14 @@ var bashTool = {
1710
1731
  const spool = createOutputSpool({ tool: "bash", thresholdBytes: MAX_OUTPUT });
1711
1732
  function killWithTimeout(child2, timeoutMs2) {
1712
1733
  if (isWin2) {
1713
- if (typeof child2.pid === "number" && child2.exitCode === null && killWin32Tree(child2.pid)) {
1714
- const fallback = setTimeout(() => {
1715
- if (child2.exitCode === null) {
1716
- try {
1717
- child2.kill();
1718
- } catch {
1719
- }
1734
+ if (typeof child2.pid === "number" && child2.exitCode === null) {
1735
+ const attempted = registry.kill(child2.pid, { force: true, graceMs: timeoutMs2 });
1736
+ if (!attempted) {
1737
+ try {
1738
+ child2.kill();
1739
+ } catch {
1720
1740
  }
1721
- }, 2e3);
1722
- timers.push(fallback);
1723
- fallback.unref?.();
1741
+ }
1724
1742
  } else {
1725
1743
  try {
1726
1744
  child2.kill();