在Mac OS X上产生的NodeJS进程的pipe道中未处理的stream错误

伙计们! 我正在尝试在NodeJS下构build自己的git服务器。 使用HTTP所有的作品都很好,但是我在ssh2会话中推送过程中遇到了问题。

client.on('session', (accept, reject) => { accept() .on('exec', (accept, reject, info) => { let channel = accept(), command = info.command, regexp = /git-(upload|receive)-pack\'\/(.*?).git\'$/, matches = command.match(regexp); //.. some code //.. command looks like 'git-receive-pack /Users/mykhailobielan/projects/git_server/repos/06565f90-9e22-11e7-94e7-815f98a3fa17.git' command = command.split(' '); var child = spawn(command.shift(), command); child.stdout.pipe(channel); channel.pipe(child.stdin); channel.on('close', (code) => channel.exit(0)); channel.on('error', (code) => channel.exit(1)); child.stdout.on('error', (data) => channel.exit(1)); child.stdin.on('error', (data) => channel.exit(1)); child.stdout.on('data', (data) => channel.exit(0)); }); }); 

当我添加最后一行child.stdout.on('data',(data)=> channel.exit(0))时,所有在Ubuntu上工作,但在Mac OS X上失败,错误:

 Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 280 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: internal/streams/legacy.js:59 remote: throw er; // Unhandled stream error in pipe. remote: ^ remote: remote: Error: connect ECONNREFUSED 127.0.0.1:32590 remote: at Object._errnoException (util.js:1026:11) remote: at _exceptionWithHostPort (util.js:1049:20) remote: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1174:14) To ssh://localhost:3333/mike/project.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'ssh://mike@localhost:3333/mike/project.git' 

没有这条线的用户在两个系统上都得到错误(在Ubuntu上没有错误的解释)。

据我所知,这个错误发生在stream上没有error handling程序,但它们存在,我不能debugging内部代码…

那么,这个错误是什么,为什么总是会发生?