From 1dd2f48b7b7b2c36655019fb20d27bdc4167a151 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 3 Jul 2021 22:10:21 +0200 Subject: [PATCH 1/5] tty: enable buffering HWM was set to 0 which would cause e.g. stdout.write(...) to always return false. Refs: https://github.com/nodejs/node/pull/39246 --- deps/npm/node_modules/gauge/index.js | 8 +++++++- lib/tty.js | 1 - test/parallel/test-stdout-stderr-write.js | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-stdout-stderr-write.js diff --git a/deps/npm/node_modules/gauge/index.js b/deps/npm/node_modules/gauge/index.js index c55324008cbfaf..fdc32310b45041 100644 --- a/deps/npm/node_modules/gauge/index.js +++ b/deps/npm/node_modules/gauge/index.js @@ -223,11 +223,17 @@ Gauge.prototype._doRedraw = function () { } } if (!this._needsRedraw) return - if (!this._writeTo.write(this._gauge.show(this._status))) { + const x = this._gauge.show(this._status); + console.log("#0", x); + if (!this._writeTo.write(x)) { + console.log("#1", x) this._paused = true this._writeTo.on('drain', callWith(this, function () { + console.log("#2") this._paused = false this._doRedraw() })) + } else { + console.log("#3") } } diff --git a/lib/tty.js b/lib/tty.js index d9c576b5fd6c77..adc45f5be5f3b5 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -94,7 +94,6 @@ function WriteStream(fd) { } net.Socket.call(this, { - highWaterMark: 0, handle: tty, manualStart: true }); diff --git a/test/parallel/test-stdout-stderr-write.js b/test/parallel/test-stdout-stderr-write.js new file mode 100644 index 00000000000000..803fc70536b8ea --- /dev/null +++ b/test/parallel/test-stdout-stderr-write.js @@ -0,0 +1,8 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); + +// https://github.com/nodejs/node/pull/39246 +assert.strictEqual(process.stderr.write('asd'), true); +assert.strictEqual(process.stdout.write('asd'), true); From 48500b468dc8d3de99c65a03bb7d0c29faba5d01 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 3 Jul 2021 22:13:07 +0200 Subject: [PATCH 2/5] fixup --- deps/npm/node_modules/gauge/index.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/deps/npm/node_modules/gauge/index.js b/deps/npm/node_modules/gauge/index.js index fdc32310b45041..c55324008cbfaf 100644 --- a/deps/npm/node_modules/gauge/index.js +++ b/deps/npm/node_modules/gauge/index.js @@ -223,17 +223,11 @@ Gauge.prototype._doRedraw = function () { } } if (!this._needsRedraw) return - const x = this._gauge.show(this._status); - console.log("#0", x); - if (!this._writeTo.write(x)) { - console.log("#1", x) + if (!this._writeTo.write(this._gauge.show(this._status))) { this._paused = true this._writeTo.on('drain', callWith(this, function () { - console.log("#2") this._paused = false this._doRedraw() })) - } else { - console.log("#3") } } From 6731cde2b5d388202f4b625db444d05d95007edd Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 4 Jul 2021 00:29:35 +0200 Subject: [PATCH 3/5] fixup --- lib/internal/bootstrap/switches/is_main_thread.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/bootstrap/switches/is_main_thread.js b/lib/internal/bootstrap/switches/is_main_thread.js index 01b2d5bd286071..6c9a2b17af5f45 100644 --- a/lib/internal/bootstrap/switches/is_main_thread.js +++ b/lib/internal/bootstrap/switches/is_main_thread.js @@ -148,7 +148,7 @@ function getStdin() { switch (guessHandleType(fd)) { case 'TTY': const tty = require('tty'); - stdin = new tty.ReadStream(fd); + stdin = new tty.ReadStream(fd, { highWaterMark: 0 }); break; case 'FILE': From 4e96f9ff4b4b0b4acb961760479da81a4a92956b Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 5 Jul 2021 06:06:53 +0200 Subject: [PATCH 4/5] Update lib/internal/bootstrap/switches/is_main_thread.js --- lib/internal/bootstrap/switches/is_main_thread.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/bootstrap/switches/is_main_thread.js b/lib/internal/bootstrap/switches/is_main_thread.js index 6c9a2b17af5f45..01b2d5bd286071 100644 --- a/lib/internal/bootstrap/switches/is_main_thread.js +++ b/lib/internal/bootstrap/switches/is_main_thread.js @@ -148,7 +148,7 @@ function getStdin() { switch (guessHandleType(fd)) { case 'TTY': const tty = require('tty'); - stdin = new tty.ReadStream(fd, { highWaterMark: 0 }); + stdin = new tty.ReadStream(fd); break; case 'FILE': From 82836705f34dde1fe087096b3e17151e12b6cb8f Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 5 Jul 2021 21:54:29 +0200 Subject: [PATCH 5/5] fixup: readableHighWaterMark --- lib/tty.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tty.js b/lib/tty.js index adc45f5be5f3b5..33e7c26f0291ed 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -57,7 +57,7 @@ function ReadStream(fd, options) { } net.Socket.call(this, { - highWaterMark: 0, + readableHighWaterMark: 0, handle: tty, manualStart: true, ...options @@ -94,6 +94,7 @@ function WriteStream(fd) { } net.Socket.call(this, { + readableHighWaterMark: 0, handle: tty, manualStart: true });