-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EIO when process ends #178
Comments
It seems that something wrong with my system (I can't reproduce it using |
It happens on
and on
and on
|
Are you on Windows running through WSL? |
No, I use Debian on my laptop and Ubuntun on VPS. |
Perhaps some race condition is happening? Does the same occur if you wrap the exit write in a |
Yes, the following also gets error:
|
Well |
I've had at least one user report the issue above and I can also reproduce locally. It happens as part of normal program execution and afterwards exit callback is invoked with (0, 0). |
i can reproduce this when the command i run doesn't produce stdout. pty.spawn('sh', ['-c', 'sleep 1'])
// or
pty.spawn('sh', ['-c', 'echo hi && sleep 1']) this produces two |
Same error on my server CenOS 8.0. const nodePty = require('node-pty');
const pty = nodePty.spawn('login', []);
pty.on('data', function(data){
process.stdout.write(data);
});
pty.on('error', function(err){
console.error('error', err);
}); WTF: After adding blocking, there will be no error const nodePty = require('node-pty');
const pty = nodePty.spawn('login', []);
const now = Date.now();
while(Date.now() < (now + 50)){ // blocking
}
pty.on('data', function(data){
process.stdout.write(data);
});
pty.on('error', function(err){
console.error('error', err);
}); |
This is because pty'fd is in non-blocking mode. It happened at the end, not bad, the worst happened at the beginning. Just like above. // Fixed with my cheap server CenOS 8.0.
const fs = require('fs');
const nodePty = require('node-pty');
const encoding = 'utf-8';
const pty = nodePty.spawn('login', [], { encoding });
pty.on('data', function(data){
process.stdout.write(data);
});
let isClose = false;
pty.on('close', function(){
isClose = true;
console.log('close');
});
pty.on('error', function(err){
setTimeout(() => {
if(isClose && (error.code === "EIO" ||
error.code === "EAGAIN" ||
error.code === "EBADF" ||
error.code === "EWOULDBLOCK")){ // Ignore the end error.
return;
}
console.error('error', err);
});
});
const firstBuffer = blockingWhenUnReadable(pty._fd); // Block in the beginning
pty.emit('data', firstBuffer.toString(encoding));
function blockingWhenUnReadable(fd){
const buffer = Buffer.alloc(1);
let isContinue = true;
while(isContinue){
try {
fs.readSync(fd, buffer);
isContinue = false;
} catch(e){
// console.error('err.code', e.code);
if(e.code === 'EAGAIN' ||
e.code === "EIO" ||
e.code === "EWOULDBLOCK"){
isContinue = true;
} else {
throw e;
}
}
}
return buffer;
} |
How to reproduce:
The text was updated successfully, but these errors were encountered: