Skip to content

Commit 4611389

Browse files
committed
tty: don't read from console stream upon creation
The tty.ReadStream constructor initializes this as a socket, which causes a read to be initiated. Even though during stdin initalization we call readStop shortly after, the read operation can consume keypress events from the system buffers. Fixes: nodejs#5384 PR-URL: nodejs#5776 Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com> Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
1 parent f429fe1 commit 4611389

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/tty.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,23 @@ function ReadStream(fd, options) {
1717
if (!(this instanceof ReadStream))
1818
return new ReadStream(fd, options);
1919

20+
// pauseOnCreate to avoid reading from the sytem buffer
2021
options = util._extend({
2122
highWaterMark: 0,
2223
readable: true,
2324
writable: false,
24-
handle: new TTY(fd, true)
25+
handle: new TTY(fd, true),
26+
pauseOnCreate: true
2527
}, options);
2628

2729
net.Socket.call(this, options);
2830

2931
this.isRaw = false;
3032
this.isTTY = true;
33+
34+
// Let the stream resume automatically when 'data' event handlers
35+
// are added, even though it was paused on creation
36+
this._readableState.flowing = null;
3137
}
3238
inherits(ReadStream, net.Socket);
3339

0 commit comments

Comments
 (0)