@mastra/e2b 0.16.1-alpha.0 → 0.16.1

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/index.js CHANGED
@@ -527,6 +527,20 @@ var FilesApiFilesystem = class extends MastraFilesystem {
527
527
  throw new Error(`${operation} ${subject} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
528
528
  }
529
529
  };
530
+ const KILL_DESCENDANTS_TIMEOUT_MS = 1e4;
531
+ /**
532
+ * A shell command that kills every process `pid` started, at any depth, but
533
+ * not `pid` itself. It pauses `pid` first: a wrapper like npm exits on its own
534
+ * once its child dies, and `kill(pid)` would then report it wasn't running.
535
+ */
536
+ function killDescendants(pid) {
537
+ return [
538
+ `kill -STOP ${pid}`,
539
+ "kill_children() { for child in $(pgrep -P \"$1\"); do kill -STOP \"$child\"; (kill_children \"$child\"); kill -KILL \"$child\"; done; }",
540
+ `kill_children ${pid}`,
541
+ "true"
542
+ ].join("\n");
543
+ }
530
544
  /**
531
545
  * Output callbacks for `run`/`connect` that hold output until the handle
532
546
  * exists. The SDK's handle reads events from construction, before `run()`
@@ -629,7 +643,16 @@ var CommandsApiProcessHandle = class extends ProcessHandle {
629
643
  }
630
644
  async kill() {
631
645
  if (this.exitCode !== void 0) return false;
632
- return this.manager.runCommands("kill", (commands) => commands.kill(this.inner.pid));
646
+ return this.manager.runCommands("kill", async (commands) => {
647
+ try {
648
+ await (await commands.run(killDescendants(this.inner.pid), {
649
+ background: true,
650
+ stdin: false,
651
+ timeoutMs: KILL_DESCENDANTS_TIMEOUT_MS
652
+ })).wait();
653
+ } catch {}
654
+ return commands.kill(this.inner.pid);
655
+ });
633
656
  }
634
657
  async sendStdin(data) {
635
658
  if (this.exitCode !== void 0) throw new Error(`Process ${this.pid} has already exited with code ${this.exitCode}`);