MCPcopy Create free account
hub / github.com/getsentry/XcodeBuildMCP / terminateProcess

Function terminateProcess

src/mcp/tools/swift-package/active-processes.ts:59–96  ·  view source on GitHub ↗
(
  info: ProcessInfo,
  timeoutMs: number,
)

Source from the content-addressed store, hash-verified

57}
58
59async function terminateProcess(
60 info: ProcessInfo,
61 timeoutMs: number,
62): Promise<{ usedForceKill?: boolean; error?: string }> {
63 try {
64 info.process.kill('SIGTERM');
65 } catch (error) {
66 return { error: error instanceof Error ? error.message : String(error) };
67 }
68
69 const alreadyExited = info.process.exitCode != null || info.process.signalCode != null;
70 if (alreadyExited) {
71 return {};
72 }
73
74 let usedForceKill = false;
75
76 const exitPromise = new Promise<'exited'>((resolve) => {
77 const onExit = (): void => resolve('exited');
78 if (typeof info.process.once === 'function') {
79 info.process.once('exit', onExit);
80 return;
81 }
82 info.process.on('exit', onExit);
83 });
84
85 const outcome = await Promise.race([exitPromise, createTimeoutPromise(timeoutMs)]);
86 if (outcome === 'timed_out') {
87 try {
88 info.process.kill('SIGKILL');
89 usedForceKill = true;
90 } catch {
91 // ignore
92 }
93 }
94
95 return { usedForceKill };
96}
97
98export async function terminateTrackedProcess(
99 pid: number,

Callers 1

terminateTrackedProcessFunction · 0.85

Calls 3

createTimeoutPromiseFunction · 0.70
killMethod · 0.65
onceMethod · 0.65

Tested by

no test coverage detected