diff options
author | Matteo Collina <hello@matteocollina.com> | 2018-07-03 18:35:59 +0200 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2018-08-22 16:41:54 +0200 |
commit | 91eec00ca20a54b1dc010cfc2fb34bc2f39eab6b (patch) | |
tree | 6dfcf264b13f29079aa97fbb64c7b4e1a61cc783 /lib/tty.js | |
parent | 6acb55041b53021171019ad755b72515a3712a9e (diff) | |
download | android-node-v8-91eec00ca20a54b1dc010cfc2fb34bc2f39eab6b.tar.gz android-node-v8-91eec00ca20a54b1dc010cfc2fb34bc2f39eab6b.tar.bz2 android-node-v8-91eec00ca20a54b1dc010cfc2fb34bc2f39eab6b.zip |
tty: make _read throw ERR_TTY_WRITABLE_NOT_READABLE
This change avoid an 'read ENOTCONN' error introduced by libuv 1.20.0
when trying to read from a TTY WriteStream. Instead, we are throwing
a more actionable ERR_TTY_WRITABLE_NOT_READABLE.
Fixes: https://github.com/nodejs/node/issues/21203
PR-URL: https://github.com/nodejs/node/pull/21654
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/tty.js')
-rw-r--r-- | lib/tty.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/tty.js b/lib/tty.js index b36adf2534..5e0e528c7e 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -25,7 +25,11 @@ const { inherits, _extend } = require('util'); const net = require('net'); const { TTY, isTTY } = process.binding('tty_wrap'); const errors = require('internal/errors'); -const { ERR_INVALID_FD, ERR_TTY_INIT_FAILED } = errors.codes; +const { + ERR_INVALID_FD, + ERR_TTY_INIT_FAILED, + ERR_TTY_WRITABLE_NOT_READABLE +} = errors.codes; const { getColorDepth } = require('internal/tty'); // Lazy loaded for startup performance. @@ -122,6 +126,13 @@ WriteStream.prototype._refreshSize = function() { } }; +// A WriteStream is not readable from, so _read become a no-op. +// this method could still be called because net.Socket() +// is a duplex +WriteStream.prototype._read = function() { + this.destroy(new ERR_TTY_WRITABLE_NOT_READABLE()); +}; + // Backwards-compat WriteStream.prototype.cursorTo = function(x, y) { if (readline === undefined) readline = require('readline'); |