在Mac OS X上生成的NodeJS进程的管道中未处理的流错误

时间:2017-09-25 11:10:14

标签: node.js ssh stream

家伙!我正在尝试在NodeJS下构建自己的git服务器。使用http all工作得很好,但是在ssh2会话中 push 期间我遇到了管道问题。

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上没有错误解释)。

据我所知,当流上没有错误处理程序但是它们存在且我无法调试内部代码时会发生此错误...

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

0 个答案:

没有答案