{"record":{"id":"8c6985c322e8e7e4","repo":"nanocoai/nanoclaw","slug":"ncl-cli-server-connection-error","errorCode":null,"errorMessage":"ncl CLI server connection error","messagePattern":"ncl CLI server connection error","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/cli/socket-server.ts","lineNumber":68,"sourceCode":"  const s = server;\n  server = null;\n  await new Promise<void>((resolve) => s.close(() => resolve()));\n}\n\nfunction handleConnection(conn: net.Socket): void {\n  let buffer = '';\n  conn.on('data', (chunk) => {\n    buffer += chunk.toString('utf8');\n    let idx: number;\n    while ((idx = buffer.indexOf('\\n')) >= 0) {\n      const line = buffer.slice(0, idx).trim();\n      buffer = buffer.slice(idx + 1);\n      if (!line) continue;\n      void handleFrame(conn, line);\n    }\n  });\n  conn.on('error', (err) => {\n    log.warn('ncl CLI server connection error', { err });\n  });\n}\n\nasync function handleFrame(conn: net.Socket, line: string): Promise<void> {\n  let req: RequestFrame;\n  try {\n    const parsed: unknown = JSON.parse(line);\n    if (!isRequestFrame(parsed)) throw new Error('bad request shape');\n    req = parsed;\n  } catch (e) {\n    write(conn, {\n      id: 'unknown',\n      ok: false,\n      error: {\n        code: 'transport-error',\n        message: `bad frame: ${e instanceof Error ? e.message : String(e)}`,\n      },\n    });","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/nanocoai/nanoclaw/blob/294ef2aee85218b23ad30eda9dfe10e590b54a8c/src/cli/socket-server.ts#L50-L86","documentation":"A client connection to the ncl CLI Unix socket emitted an error event. This is a transport-level warning about a single connection (usually a client disconnecting abruptly), not a host failure; the server keeps running.","triggerScenarios":"An `ncl` client process is killed mid-request, a malformed client connects and resets, or the socket is closed while a frame is still being written.","commonSituations":"Users Ctrl-C an ncl invocation, scripting timeouts that kill ncl, or health probes opening/closing the socket rapidly.","solutions":["Usually ignorable if ncl commands otherwise succeed","Correlate timestamps with aborted ncl invocations to confirm cause","If persistent, inspect client-side errors (e.g. `ncl --json ...` output) for the real failure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"conn.on('error', err => { /* log and ignore per-connection errors; server stays up */ });","preventionTips":["Don't kill ncl clients mid-request in scripts; use timeouts that read the response","Treat single-connection errors as noise unless commands fail"],"tags":["ncl","unix-socket","connection","transport"],"backgroundTag":"client-connection-reset","analyzedSha":"294ef2aee85218b23ad30eda9dfe10e590b54a8c","analyzedAt":"2026-08-28T13:59:10.357Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}