can1357/oh-my-pi · error · Error

Failed to stop ${holder.image} (PID ${holder.pid})

Error message

Failed to stop ${holder.image} (PID ${holder.pid})

What it means

terminatePortHolder() in the stats package sends SIGTERM to the process occupying the stats port. If that kill(2) call fails with anything other than ESRCH (process already gone), the error is wrapped and rethrown with the holder's image name and PID. This means the runtime could not even deliver the signal — usually a permissions problem.

Source

Thrown at packages/stats/src/port-conflict.ts:199

	if (!powershell) return { pid, image, commandLine: "" };
	const command = `(Get-CimInstance Win32_Process -Filter "ProcessId = ${pid}").CommandLine`;
	const processInfo = await $`${powershell} -NoProfile -NonInteractive -Command ${command}`.quiet().nothrow();
	return { pid, image, commandLine: processInfo.exitCode === 0 ? processInfo.text().trim() : "" };
}

async function findPortHolder(port: number): Promise<PortHolder | null> {
	if (process.platform === "linux") return findLinuxPortHolder(port);
	if (process.platform === "darwin") return findMacPortHolder(port);
	if (process.platform === "win32") return findWindowsPortHolder(port);
	return null;
}

async function terminatePortHolder(holder: PortHolder): Promise<void> {
	try {
		process.kill(holder.pid, "SIGTERM");
	} catch (error) {
		if (error instanceof Error && "code" in error && error.code === "ESRCH") return;
		throw new Error(`Failed to stop ${holder.image} (PID ${holder.pid})`, { cause: error });
	}

	for (let attempt = 0; attempt < PROCESS_EXIT_POLLS; attempt++) {
		await Bun.sleep(PROCESS_EXIT_POLL_MS);
		try {
			process.kill(holder.pid, 0);
		} catch (error) {
			if (error instanceof Error && "code" in error && error.code === "ESRCH") return;
			throw new Error(`Failed to inspect ${holder.image} (PID ${holder.pid})`, { cause: error });
		}
	}

	try {
		process.kill(holder.pid, "SIGKILL");
	} catch (error) {
		if (error instanceof Error && "code" in error && error.code === "ESRCH") return;
		throw new Error(`Failed to kill ${holder.image} (PID ${holder.pid})`, { cause: error });
	}

View on GitHub (pinned to 9690622007)

Solutions

  1. Stop the offending process manually with elevated privileges (sudo kill <pid>)
  2. Run the omp stats server as the same user that owns the port holder
  3. Identify the holder (ps -p <pid>) and free the port another way, or point stats at a different port
  4. If the process is in an uninterruptible state, resolve the underlying hang before reclaiming

Example fix

// before
await reclaimStatsPort(port); // throws 'Failed to stop omp (PID 1234)'
// after
try {
  await reclaimStatsPort(port);
} catch (err) {
  console.error(`Reclaim failed: ${err.message}; stop PID manually: sudo kill <pid>`);
}
Defensive patterns

Strategy: try-catch

Validate before calling

try {
  process.kill(holder.pid, 0);
} catch (err) {
  if (err.code === 'EPERM') console.error(`PID ${holder.pid} not signalable by current user; elevated kill required`);
}

Type guard

function isNodeErrno(err: unknown): err is NodeJS.ErrnoException {
  return err instanceof Error && typeof (err as NodeJS.ErrnoException).code === 'string';
}

Try / catch

try {
  await reclaimStatsPort(port);
} catch (err) {
  if (err.message.startsWith('Failed to stop')) {
    console.error(`${err.message} — stop it manually: sudo kill <pid>`);
  } else throw err;
}

Prevention

When it happens

Trigger: process.kill(holder.pid, 'SIGTERM') throwing EPERM (process owned by another user), EINVAL, or any non-ESRCH errno while reclaiming the stats port via reclaimStatsPort.

Common situations: The port is held by a process started under a different user or via sudo; containerized setups where the PID is visible but not signalable; a stale/wrapped PID whose signal is denied by the OS; hardened sandbox blocking signals.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/b7ce67961a6a2d3b. Report an issue: GitHub.