天天看點

Nodejs cluster報錯Error [ERR_IPC_CHANNEL_CLOSED]: channel closed

這個錯誤是在Master程序向子程序send消息時發現pipe已經關閉了的情況下由Master程序報出來的。

2019-12-16 14:33:02,pid-170096, Error [ERR_IPC_CHANNEL_CLOSED]: channel closed
    at ChildProcess.target.send (internal/child_process.js:578:16)
    at Worker.send (internal/cluster/worker.js:54:28)
           

經排查這個問題原因是子程序占用記憶體太多,觸發了Linux核心的OOM Killer機制通過SIGKILL信号kill掉了子程序。在Centos 6上檢視/var/log/messages可以找到相關日志:

[email protected]:/var/log> grep "Kill" messages | grep node
Dec 16 14:33:00 8_17 kernel: Out of memory: Kill process 170341 (node) score 8 or sacrifice child
Dec 16 14:33:00 8_17 kernel: Killed process 170341, UID 0, (node) total-vm:2174692kB, anon-rss:1251432kB, file-rss:8kB
Dec 16 14:35:54 8_17 kernel: Out of memory: Kill process 175318 (node) score 8 or sacrifice child
Dec 16 14:35:54 8_17 kernel: Killed process 175318, UID 0, (node) total-vm:2175532kB, anon-rss:1252000kB, file-rss:40kB
Dec 16 14:42:04 8_17 kernel: Out of memory: Kill process 184236 (node) score 8 or sacrifice child
Dec 16 14:42:04 8_17 kernel: Killed process 184236, UID 0, (node) total-vm:2186980kB, anon-rss:1264544kB, file-rss:172kB
Dec 16 14:42:04 8_17 kernel: Out of memory: Kill process 184240 (node) score 8 or sacrifice child
Dec 16 14:42:04 8_17 kernel: Killed process 184240, UID 0, (node) total-vm:2186980kB, anon-rss:1264544kB, file-rss:172kB
Dec 16 14:42:32 8_17 kernel: Out of memory: Kill process 184250 (node) score 9 or sacrifice child
Dec 16 14:42:32 8_17 kernel: Killed process 184250, UID 0, (node) total-vm:2213728kB, anon-rss:1290780kB, file-rss:208kB
Dec 16 14:43:08 8_17 kernel: Out of memory: Kill process 184629 (node) score 10 or sacrifice child
Dec 16 14:43:08 8_17 kernel: Killed process 184629, UID 0, (node) total-vm:2229684kB, anon-rss:1307020kB, file-rss:664kB
Dec 16 14:43:08 8_17 kernel: Out of memory: Kill process 184277 (node) score 9 or sacrifice child
Dec 16 14:43:08 8_17 kernel: Killed process 184277, UID 0, (node) total-vm:2216760kB, anon-rss:1291796kB, file-rss:616kB