Node:child_process.js:427 throw new TypeError(“This handle type can not be sent”);

在subprocess中使用process.send时出现错误,如下所示:

process.send(someObject, function() { .... }); 

subprocess创build如下:

  var child = require('child_process'); var forkedProcess = child.fork(nodeScriptFile); 

错误是:

 child_process.js:427 throw new TypeError("This handle type can't be sent"); ^ TypeError: This handle type can't be sent 

程序在一台服务器上正常工作。 我试图通过复制所有文件创build一个单独的生产服务器,我开始得到这个错误。 当然,还有更多的程序,那么上面显示的代码。 我觉得我忽略了一些安装或者一些小事。 我看着child-process.js代码,并从这个代码触发错误:

  if (handle instanceof net.Socket) { message.type = 'net.Socket'; } else if (handle instanceof net.Server) { message.type = 'net.Server'; } else if (handle instanceof process.binding('tcp_wrap').TCP || handle instanceof process.binding('pipe_wrap').Pipe) { message.type = 'net.Native'; } else if (handle instanceof dgram.Socket) { message.type = 'dgram.Socket'; } else if (handle instanceof process.binding('udp_wrap').UDP) { message.type = 'dgram.Native'; } else { throw new TypeError("This handle type can't be sent"); } 

花了相当多的时间…请帮助!

在旧版本的Node中(0.10或者0.12), process.send()是同步的,所以它不接受callback函数。 但是,它确实接受了一个可选的第二个参数sendHandle

在你的情况下,你使用的是较旧的Node版本,因为你的callback函数参数不是.send()一个有效参数,所以抛出了错误,因此它通过了你显示的所有handle instanceof ...testing你的问题。