Node.js Mac OS X上生成的NodeJS进程的管道中存在未经处理的流错误
伙计们!我正在尝试在NodeJS下构建自己的git服务器。有了http,一切正常,但我在ssh2会话中的推送过程中遇到了管道问题Node.js Mac OS X上生成的NodeJS进程的管道中存在未经处理的流错误,node.js,ssh,stream,Node.js,Ssh,Stream,伙计们!我正在尝试在NodeJS下构建自己的git服务器。有了http,一切正常,但我在ssh2会话中的推送过程中遇到了管道问题 client.on('session', (accept, reject) => { accept() .on('exec', (accept, reject, info) => { let channel = accept(), command = info.command,
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));
});
});
当我在('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上没有错误解释)
据我所知,当流中并没有错误处理程序时,就会发生此错误,但它们是存在的,并且我无法调试内部代码
那么,这个错误是关于什么的?为什么总是发生这个错误?当您收到一块标准输出数据时,发送退出代码似乎是不正确的。您应该在
child.on('exit',…)
和channel.close()上调用channel.exit(x)
,在child.on('close',…)
上调用channel.exit(x)
,但它工作正常(因为我认为在标准数据流中不会丢失任何数据)。我尝试在生成的进程上使用close
和exit
事件,但仍然不起作用(相同的错误)…在收到一块标准输出数据时发送退出代码似乎不正确。您应该在child.on('exit',…)
和channel.close()上调用channel.exit(x)
,在child.on('close',…)
上调用channel.exit(x)
,但它工作正常(因为我认为在标准数据流中不会丢失任何数据)。我在生成的进程上尝试了close
和exit
事件,但仍然不起作用(相同的错误)。。。