{"record":{"id":"21e049977a7c53d6","repo":"diegosouzapw/OmniRoute","slug":"tproxy-capture-mode-is-already-running","errorCode":null,"errorMessage":"TPROXY capture mode is already running","messagePattern":"TPROXY capture mode is already running","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mitm/tproxy/captureManager.ts","lineNumber":74,"sourceCode":"}\n\ninterface ActiveCapture {\n  handle: TproxyCaptureHandle;\n  startedAt: string;\n  intercepts: { count: number };\n}\n\nlet active: ActiveCapture | null = null;\n\n/**\n * Start the decrypt-capable TPROXY capture mode. Rejects if a session is already\n * running or the native addon is unavailable. The dynamic CA is created here and\n * installed in the trust store via the injected `installCa`.\n */\nexport async function startCaptureMode(\n  options: StartCaptureModeOptions\n): Promise<CaptureManagerStatus> {\n  if (active) throw new Error(\"TPROXY capture mode is already running\");\n\n  const deps: CaptureManagerDeps = { ...realDeps, ...options.deps };\n  if (!deps.isAvailable()) {\n    throw new Error(\"TPROXY capture mode requires the native addon (Linux + CAP_NET_ADMIN).\");\n  }\n\n  const certStore = deps.createCertStore();\n  const intercepts = { count: 0 };\n  const handle = await deps.startTproxyCapture(options.cfg, {\n    decrypt: { certStore, installCa: options.installCa, uninstallCa: options.uninstallCa },\n    onIntercept: () => {\n      intercepts.count += 1;\n    },\n  });\n  active = { handle, startedAt: deps.now(), intercepts };\n  return getCaptureStatus();\n}\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/mitm/tproxy/captureManager.ts#L56-L92","documentation":"Singleton guard in startCaptureMode: the module-level `active` capture session is non-null, so a second decrypt-capable TPROXY capture cannot start — iptables rules and the dynamic CA are bound to the existing session. Means stop the current capture before starting a new one; not an error of the capture machinery itself.","triggerScenarios":"Thrown at src/mitm/tproxy/captureManager.ts:74 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call stop on the active capture session first","Query the capture status to reuse the running session","Serialize start/stop calls from the UI or API layer"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}