diegosouzapw/OmniRoute · error · Error

MITM server is already starting

Error message

MITM server is already starting

What it means

TOCTOU guard in startMitm: tryAcquire on the mitmStarting mutex failed, meaning another startMitm() call is already in flight in this process. Prevents two concurrent starts from racing to spawn the server process; the caller should await the in-flight start rather than spawn a second one.

Solutions

  1. Retry/await — poll status until the in-flight start completes or fails
  2. Serialize startMitm calls at the API layer so only one is issued at a time
  3. If stuck, stopMitm and start clean
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/mitm/manager.ts:453 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/30a6d2e6814c0d26. Report an issue: GitHub.

Appendix: source

Thrown at src/mitm/manager.ts:453

/**
 * Start MITM proxy
 * @param {string} apiKey - OmniRoute API key
 * @param {string} sudoPassword - Sudo password for DNS/cert operations
 */
export async function startMitm(
  apiKey: string,
  sudoPassword: string,
  options: { port?: number } = {}
): Promise<{ running: true; pid: number | null; certTrusted: boolean }> {
  // Check if already running
  if (serverProcess && !serverProcess.killed) {
    throw new Error("MITM proxy is already running");
  }

  // Check if another startMitm() call is already in flight (TOCTOU guard —
  // see the `mitmStarting` comment above).
  if (!tryAcquireMitmStartLock()) {
    throw new Error("MITM server is already starting");
  }

  try {
    return await startMitmInternal(apiKey, sudoPassword, options);
  } finally {
    releaseMitmStartLock();
  }
}

/**
 * Internal body of startMitm(), extracted so the single-flight lock in
 * startMitm() cleanly wraps it in try/finally without re-indenting the
 * entire implementation.
 */
async function startMitmInternal(
  apiKey: string,
  sudoPassword: string,
  options: { port?: number }

View on GitHub (pinned to a179ffed5b)