如果 ClusterSettings
的 serialization
键设为 "json"
或不设置,则 Error 的内容是不能正常传递的,只能得到一个空对象。
默认设置下,IPC 可能适合传递小数据。
[Running] ts-node "c:\Users\lightyears\Source\test\src\Test.ts" | |
c:\Users\lightyears\Source\test\src\Test.ts:16 | |
throw new Error("GG!") | |
^ | |
Error: GG! | |
at Timeout._onTimeout (c:\Users\lightyears\Source\test\src\Test.ts:16:15) | |
at listOnTimeout (internal/timers.js:551:17) | |
at processTimers (internal/timers.js:494:7) | |
[BEGIN OF MESSAGE] Error: GG! | |
at Timeout._onTimeout (c:\Users\lightyears\Source\test\src\Test.ts:16:15) | |
at listOnTimeout (internal/timers.js:551:17) | |
at processTimers (internal/timers.js:494:7) [END OF MESSAGE] | |
[Done] exited with code=0 in 3.182 seconds |
import cluster from "cluster"; | |
if (cluster.isMaster) { | |
cluster.setupMaster({ | |
serialization: 'advanced' | |
} as cluster.ClusterSettings) | |
cluster.fork(); | |
cluster.on('message', (_, msg) => { | |
console.log("[BEGIN OF MESSAGE]", msg, '[END OF MESSAGE]') | |
}) | |
} else { | |
setTimeout(() => { | |
throw new Error("GG!") | |
}, 200); | |
process.on('uncaughtExceptionMonitor', err => { | |
process.send && process.send(err); | |
}) | |
} |