diegosouzapw/OmniRoute · error · Error

MITM proxy is already running

Error message

MITM proxy is already running

What it means

State guard in startMitm: the module still holds a live serverProcess handle (not killed), so a second start would orphan the running MITM proxy. Means the proxy is already up in this process — call stopMitm first or reuse the existing instance; this is an idempotency rejection, not a failure.

Solutions

  1. Use the running instance (check status/getState) instead of starting again
  2. Call stopMitm() and wait for shutdown before starting again
  3. Verify serverProcess.killed is not stale after a crash (mitmStarting guard also exists)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/mitm/manager.ts:447 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/a9edbbdb94ca77cd. Report an issue: GitHub.

Appendix: source

Thrown at src/mitm/manager.ts:447

    dnsConfigured,
    certExists,
    orphanedStateDetected: _orphanedStateDetected,
  };
}

/**
 * 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

View on GitHub (pinned to a179ffed5b)