-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Losing keystrokes when using tty.ReadStream() over process.stdin #5574
Comments
Can you perhaps create a test case that applies to last 0.12.x and 4.x (branches you can reproduce on) we then can add to the test suite or similar? |
Here you have a minimal test where you can be able to replicate the problem: var Interface = require('readline').Interface
var ReadStream = require('tty').ReadStream
var spawn = require('child_process').spawn
var rl = Interface(process.stdin, process.stdout)
rl.prompt()
var input = rl.input
var stdin = ReadStream(input.fd)
input.pause()
var stdio = [stdin, rl.output]
var cp = spawn('cat', [], {stdio: stdio}) When you run it forget about the |
I've done some more tests and simplified a little bit the test to replicate the problem: var Interface = require('readline').Interface
var ReadStream = require('tty').ReadStream
var spawn = require('child_process').spawn
Interface(process.stdin, process.stdout)
var stdin = ReadStream(process.stdin.fd)
process.stdin.pause()
var stdio = [stdin, process.stdout]
spawn('cat', [], {stdio: stdio}) Things I've found so far:
|
Hmmm, not seeing anything as far as I can tell. v5.7.1 & OS X 10.10.5 |
Sounds similar to #5384 |
I've done some more tests: if I don't create the instance of It seems that we have here two important bugs, maybe related between them:
I was thinking in my use case to do a backup of the file descriptor 0, use it and later restore it, but probably it will not work due to
I have just checked it with Node.js v5.7.1 on Ubuntu 15.10 32 bits and I got still the problem... :-(
Seems similar, but there they are loosing the first input line on Windows and here I'm losing some random chars and keystrokes on Linux. On nsh, one level works fine, if I launch inside it another one or any other interactive cli (like nano) drops are about 50% (sometimes I can write correctly 9 kyestrokes without loses, other times it doesn't get anyone), and if I launch inside a third level shell (inception ;-) ) I hardly get any keystroke at all and need to kill the process from outside. |
Checked that the problem also exists on Node.js v4.3.2 on OS X 10.11.3 (15D21) "El Capitan", so it's not a Linux-only bug. |
I've been able to recreate the problem in an automated test at https://gist.github.com/piranna/7dc47f387ecdcf739a19. It works by spawning a process with the code from the previous snippets and pipping to its stdin a readable stream that send characters from a string at a normal typing rate of 240 keystrokes per minute (the frequency doesn't matter, the problem happens both as slow as 60 keystrokes per minute or as fast as 120 keystrokes per second). If you exec it several times, you'll see that on each of them some random characters from the inital string (
I've also seen that although I'm sending Could/should this automated test be included on Node.js ones? |
How could I do? Checkout that pull-request and compile it myself to see if it works (It's not a problem for me, just want to be sure if that's what you say)?
The gist I've put in the previous comment is an automated test, although I'm not using the |
@piranna: Yes, that's what @santigimeno is suggesting. A guide on how to apply a PR as patch can be found here (stop after patch): https://github.com/nodejs/node/blob/master/COLLABORATOR_GUIDE.md#technical-howto ..after that, compile as needed and run your code again. |
Yes, what @jbergstroem said.
I would create a new test in |
I've follow your instruction and seems to be fixed
I'll try later to test it with a longer text and with the master branch to compare and be sure this behaviour is directly related to the pull-request. |
Confirmed, #5776 fix this problem too :-D I didn't test it with a long test, but until that I'll request them to backport it to Node.js v.4.x |
I've open a pull-request with the test for this use case. |
Test that characters from stdin are not randomly lost when using a `readline.Interface` and a `tty.ReadStream` on `process.stdin`
I have just checked this on Ubuntu 15.10 32 bits on an Intel Core2 Duo machine with the code on master having the fix #5776 and the test on my pull-request #5841 and this error still arises... :-(
My previous checks where on MacOS X "El Capitan" 64 bits, so I'm not sure if it's a Linux-only issue or a 32 bits one, I'm going to do more checks to see if I'm able to replicate it on other systems to be sure. |
Any update on this? This is still happening on Node.js v6.3.0... |
/ping @Fishrock123. Still working on this? If not, should we un-assign it so someone else might pick it up? |
I'm able to reproduce this problem in latest Current (11.9.0) but not on the master branch. @piranna Any chance this is fixed if you use one of the recent nightly builds? If so, then we can at least expect this to be fixed in 12.0.0. |
Unable to reproduce the issue now. Closing. Can reopen if necessary |
I'm rewriting nsh as a POSIX shell for NodeOS. I create a tty.ReadStream instance using file descriptor from Readline.input, that at the same time it's initialized with process.stdin. Later I pause Readline.input, and although it doesn't emit 'data' events, if I exec an interactive command like nano or an instance of Node.js (or a recursive execution of the shell), some of the keystrokes are losed about 50% of the times (but it's random) and need to press them twice. Seems like there are several readers of stdin and someone is capturing the keystrokes that sbould end on the final command...
The text was updated successfully, but these errors were encountered: