{"record":{"id":"65421850c29579ef","repo":"can1357/oh-my-pi","slug":"adapter-process-exited-before-tcp-port-host-p","errorCode":null,"errorMessage":"Adapter process exited before TCP port ${host}:${port} was ready","messagePattern":"Adapter process exited before TCP port (.+?):(.+?) was ready","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/dap/client.ts","lineNumber":852,"sourceCode":"\t\t},\n\t}).catch(error => {\n\t\tonClose?.();\n\t\treject(error);\n\t});\n\treturn promise;\n}\n\n/** Wait for a TCP DAP server and retain the first successful connection. */\nasync function waitForTcpTransport(\n\thost: string,\n\tport: number,\n\ttimeoutMs: number,\n\tproc: { exitCode: number | null },\n): Promise<SocketTransport> {\n\tconst deadline = Date.now() + timeoutMs;\n\twhile (Date.now() < deadline) {\n\t\tif (proc.exitCode !== null) {\n\t\t\tthrow new Error(`Adapter process exited before TCP port ${host}:${port} was ready`);\n\t\t}\n\t\ttry {\n\t\t\treturn await connectTcpSocket(host, port);\n\t\t} catch {\n\t\t\tawait Bun.sleep(50);\n\t\t}\n\t}\n\tthrow new Error(`TCP port ${host}:${port} was not ready after ${timeoutMs}ms`);\n}\n\n/**\n * Give the adapter a chance to announce it is listening on `port` before the\n * first connect. vscode-js-debug prints `Debug server listening at HOST:PORT`\n * to stdout from inside its `listen()` callback; waiting for the port to appear\n * there means we only connect once the child genuinely owns the reserved port,\n * which closes the WSL2-mirrored ghost-accept window (issue #6055) at its root.\n *\n * Best-effort: resolves on the banner, on process exit, or on timeout — the","sourceCodeStart":834,"sourceCodeEnd":870,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/dap/client.ts#L834-L870","documentation":"While waiting for a TCP-mode DAP adapter to start listening on host:port, the launcher observes the adapter process has exited. Since a dead process can never open the port, this error is thrown immediately rather than continuing to poll until the generic port-timeout fires.","triggerScenarios":"Adapter launched with a --server/--port TCP mode crashes at startup (bad args, missing runtime, port binding failure causing exit); the listen command exits because the configured port is invalid or privileged; adapter binary fails before entering its listen loop.","commonSituations":"Typo'd or incompatible adapter server flags; port already in use making the adapter abort; node/python runtime version mismatch for the TCP debug server; adapter crashing on invalid launch configuration JSON.","solutions":["Run the adapter's server command manually with the same host/port to capture its exit error","Fix adapter server flags/port configuration in the adapter descriptor or debug config","Check for port conflicts (another process bound to the port) and pick a free port","Capture adapter stderr at launch and check logs for the crash reason"],"exampleFix":"// before\nargs: ['--server=4711', '--unknown-flag'] // adapter exits\n// after\nargs: ['--server=4711'] // verified manually: node dbg.js --server=4711","handlingStrategy":"try-catch","validationCode":"const listening = await new Response(proc.stdout).text().then(t => t.includes('listening'));\nif (!listening && proc.exitCode !== null) throw new Error('adapter exited before listening');","typeGuard":null,"tryCatchPattern":"try {\n  await connectTcpPort(adapter, host, port, timeoutMs, proc);\n} catch (err) {\n  if (String((err as Error).message).includes('exited before TCP port')) {\n    console.error(`adapter ${adapter.name} died on startup; check its stderr and server flags`);\n  }\n  throw err;\n}","preventionTips":["Verify the adapter's TCP server flags (--server/--port) against its documented CLI","Check the configured port is free before launch (lsof/ss)","Keep adapter stderr captured; startup exits are almost always logged there","Use an adapter version whose server mode matches your config schema"],"tags":["dap","tcp","process-exit","startup"],"backgroundTag":"adapter-crashed-on-startup","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}