我应该在哪里/什么时候发现这个错误?
Error: IPC channel is already disconnected
当我多次调用时,这是从child_process
(使用cluster
)模块调用的。.disconect()
我知道我不应该两次(或多次)调用它,但有时我无法控制它。最终如何防止多次调用它?此代码不起作用:
try {
if (worker.state !== "disconnected" && worker.state !== "dead") {
worker.disconnect();
}
} catch (error) {}
编辑:
这是此错误的堆栈跟踪:
events.js:71
throw arguments[1]; // Unhandled 'error' event
^
Error: IPC channel is already disconnected
at process.target.disconnect (child_process.js:392:26)
at ProgressTracker.callback (cluster.js:437:20)
at ProgressTracker.check (cluster.js:94:32)
at Object.Worker.disconnect [as 44:2] (cluster.js:445:16)
at handleResponse (cluster.js:149:41)
at respond (cluster.js:170:5)
at handleMessage (cluster.js:180:5)
at process.EventEmitter.emit (events.js:126:20)
at handleMessage (child_process.js:269:12)
at Pipe.channel.onread (child_process.js:293:9)