{"record":{"id":"730d317a77e59397","repo":"docmirror/dev-sidecar","slug":"server-process-sigpipe-code-code-signal","errorCode":null,"errorMessage":"server process SIGPIPE, code: ${code}, signal:","messagePattern":"server process SIGPIPE, code: (.+?), signal:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/core/src/modules/server/index.js","lineNumber":119,"sourceCode":"      log.info('保存 running.json 运行时配置文件成功:', runningConfigPath)\n    } catch (e) {\n      log.error('保存 running.json 运行时配置文件失败:', runningConfigPath, ', error:', e)\n      throw e\n    }\n    const serverProcess = fork(mitmproxyPath, [runningConfigPath])\n    server = {\n      id: serverProcess.pid,\n      process: serverProcess,\n      port: serverConfig.port,\n      close () {\n        serverProcess.send({ type: 'action', event: { key: 'close' } })\n      },\n    }\n    serverProcess.on('beforeExit', (code) => {\n      log.warn('server process beforeExit, code:', code)\n    })\n    serverProcess.on('SIGPIPE', (code, signal) => {\n      log.warn(`server process SIGPIPE, code: ${code}, signal:`, signal)\n    })\n    serverProcess.on('exit', (code, signal) => {\n      log.warn(`server process exit, code: ${code}, signal:`, signal)\n    })\n    serverProcess.on('uncaughtException', (err, origin) => {\n      log.error('server process uncaughtException:', err)\n    })\n    serverProcess.on('message', (msg) => {\n      log.debug('收到子进程消息:', JSON.stringify(msg))\n      if (msg.type === 'status') {\n        fireStatus(msg.event)\n      } else if (msg.type === 'error') {\n        let code = ''\n        if (msg.event.code) {\n          code = msg.event.code\n        }\n        fireStatus(false) // 启动失败\n        event.fire('error', { key: 'server', value: code, error: msg.event, message: msg.message })","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/docmirror/dev-sidecar/blob/7710cd56cce760c708f30b01d2d4056eb8c402d5/packages/core/src/modules/server/index.js#L101-L137","documentation":"A warning log from the `SIGPIPE` handler on the forked mitmproxy child (packages/core/src/modules/server/index.js:118-120). It fires when the child process receives a SIGPIPE signal, typically caused by writing to a closed pipe — most commonly the parent (core) process died or closed the IPC stdio pipes while the child was still logging or sending messages.","triggerScenarios":"Parent core process exits/crashes while the child keeps writing to stdout or IPC channel; the IPC pipe between parent and child is closed while the child sends status/speed messages.","commonSituations":"Killing the GUI/CLI parent process (task manager, crash) leaving the orphaned mitmproxy child; terminal window closed so stdout pipe breaks; EPIPE storms when piping logs to a short-lived consumer.","solutions":["Usually a symptom, not the cause: find why the pipe broke — check whether the parent process exited and if so why (core.log/gui.log).","Ensure the child is shut down with server.close()/kill() before the parent exits so pipes close cleanly.","If running headless/daemonized, redirect child stdio to files instead of a terminal pipe (`fork(mitmproxyPath, [cfg], { stdio: ['pipe','pipe','pipe','ipc'] })` plus file logging).","Ignore 'ignore' stdio for the child if IPC is the only needed channel to avoid stdout EPIPE/SIGPIPE issues."],"exampleFix":"// before\nconst serverProcess = fork(mitmproxyPath, [runningConfigPath])\n// after\nconst serverProcess = fork(mitmproxyPath, [runningConfigPath], {\n  stdio: ['ignore', 'pipe', 'pipe', 'ipc'],\n})\nserverProcess.stdout.on('error', (e) => log.warn('child stdout pipe error:', e))","handlingStrategy":"retry","validationCode":"// before starting, ensure config is complete so the child does not drain-exit\nconst cfg = DevSidecar.api.config.get()\nif (!cfg.server || !cfg.server.port || !cfg.server.mitmproxyPath) {\n  throw new Error('server config incomplete; fix ~/.dev-sidecar/config.json before startup')\n}","typeGuard":null,"tryCatchPattern":"let restarting = false\nserverProcess.on('beforeExit', (code) => {\n  log.warn('server process beforeExit, code:', code)\n  if (!restarting) {\n    restarting = true\n    serverApi.restart({ mitmproxyPath }).finally(() => { restarting = false })\n  }\n})","preventionTips":["Keep at least one active handle (HTTP/HTTPS listener) alive in the child; investigate child code if beforeExit fires without a close request.","Monitor the warning and cross-check server.log to distinguish intentional shutdown from loop-drain bugs.","Backoff-restart the child if it exits on its own while the accelerator should be enabled.","Validate running.json parses before forking to avoid boot-time exits."],"tags":["logging","signal","sigpipe","child-process","broken-pipe"],"backgroundTag":"sigpipe-broken-pipe","analyzedSha":"7710cd56cce760c708f30b01d2d4056eb8c402d5","analyzedAt":"2026-08-31T22:07:07.234Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}