{"record":{"id":"cb43544493944e8c","repo":"stablyai/orca","slug":"could-not-reserve-a-guest-port-result-stdout","errorCode":null,"errorMessage":"Could not reserve a guest port: ${result.stdout}","messagePattern":"Could not reserve a guest port: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"config/scripts/wsl-hook-relay-reattach-benchmark.mjs","lineNumber":122,"sourceCode":"\nfunction parseEndpoint(contents) {\n  const port = Number(/ORCA_AGENT_HOOK_PORT=['\"]?(\\d+)/.exec(contents)?.[1])\n  const token = /ORCA_AGENT_HOOK_TOKEN=['\"]?([^'\"\\r\\n]+)/.exec(contents)?.[1]\n  return Number.isInteger(port) && port > 0 && token ? { port, token } : null\n}\n\nasync function freeGuestPort(distro) {\n  const result = await run(\n    'wsl.exe',\n    wslArgs(distro, [\n      '/usr/bin/python3',\n      '-c',\n      'import socket; s=socket.socket(); s.bind((\"127.0.0.1\",0)); print(s.getsockname()[1]); s.close()'\n    ])\n  )\n  const port = Number(result.stdout.trim())\n  if (!Number.isInteger(port) || port <= 0) {\n    throw new Error(`Could not reserve a guest port: ${result.stdout}`)\n  }\n  return port\n}\n\nasync function startStallingGuestServer(distro) {\n  const source = [\n    'import socket,sys,threading',\n    'stop=threading.Event()',\n    'threading.Thread(target=lambda:(sys.stdin.buffer.read(),stop.set()),daemon=True).start()',\n    'server=socket.socket()',\n    'server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)',\n    'server.bind((\"127.0.0.1\",0))',\n    'server.listen()',\n    'server.settimeout(0.1)',\n    'print(f\"READY {server.getsockname()[1]}\",flush=True)',\n    'held=[]',\n    'while not stop.is_set():',\n    ' try:',","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/scripts/wsl-hook-relay-reattach-benchmark.mjs#L104-L140","documentation":"Thrown by the WSL benchmark when a Python one-liner run inside the guest distro fails to print a usable ephemeral port number. The guest runs `socket.bind(('127.0.0.1',0))` and prints the assigned port; if stdout is non-numeric, zero, or empty, the host refuses to proceed because the relay needs a concrete port.","triggerScenarios":"python3 is missing or prints an error to stdout in the guest, the distro's PATH lacks /usr/bin/python3, WSL interop returns an error message instead of a port, or stdout has leading/trailing content that defeats Number()+trim().","commonSituations":"Minimal WSL images without python3 preinstalled, a distro where `python3` is actually a broken symlink, or wsl.exe returning an error string (e.g. distribution not registered) that lands in result.stdout.","solutions":["Install python3 in the WSL distro (apt-get install -y python3 or equivalent).","Run the failing wsl.exe command manually to see the real stdout/stderr: `wsl.exe -d <distro> /usr/bin/python3 -c 'import socket; s=socket.socket(); s.bind((\"127.0.0.1\",0)); print(s.getsockname()[1]); s.close()'`.","Confirm the distro name passed to resolveDistro is registered (`wsl.exe -l -q`).","Consider a Node-based port reservation to drop the python3 dependency."],"exampleFix":"// before\nconst port = Number(result.stdout.trim())\nif (!Number.isInteger(port) || port <= 0) {\n  throw new Error(`Could not reserve a guest port: ${result.stdout}`)\n}\n\n// after — surface stderr too and check exit status\nif (result.status !== 0) {\n  throw new Error(`Guest port probe failed (exit ${result.status}): ${result.stderr || result.stdout}`)\n}\nconst port = Number(result.stdout.trim())\nif (!Number.isInteger(port) || port <= 0) {\n  throw new Error(`Could not reserve a guest port: stdout=${JSON.stringify(result.stdout)} stderr=${JSON.stringify(result.stderr)}`)\n}","handlingStrategy":"validation","validationCode":"// Pre-check python3 exists in the guest before relying on it\nconst probe = await run('wsl.exe', wslArgs(distro, ['/bin/sh', '-c', 'command -v python3 || exit 1']), { allowFailure: true })\nif (probe.status !== 0) {\n  throw new Error(`python3 not found in distro ${distro}; install it before running the benchmark`)\n}","typeGuard":"function isPositivePortString(s: string): boolean {\n  const n = Number(s.trim())\n  return Number.isInteger(n) && n > 0 && n <= 65535\n}","tryCatchPattern":"try {\n  const port = await freeGuestPort(distro)\n} catch (err) {\n  // Inspect result.stderr captured by run() to distinguish missing-python from a bind failure\n  throw err\n}","preventionTips":["Document the python3 prerequisite in the benchmark README.","Consider a Node-based port probe to drop the python dependency entirely.","Always include stderr alongside stdout in reservation-failure messages."],"tags":["wsl","benchmark","networking","python","port-allocation"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}