From 6fa51d6198e9863c2e8a8ccf6895fd631eac6afc Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 15 Oct 2017 22:40:00 +0200 Subject: [PATCH] tty: fix 'resize' event regression It's not wholly clear what commit introduced the regression but between v8.4.0 and v8.5.0 the 'resize' event stopped getting emitted when the tty was resized. The SIGWINCH event listener apparently was being installed before the support code for `process.on('SIGWINCH', ...)` was. Fix that by moving said support code to real early in the bootstrap process. This commit also seems to fix a Windows-only "write EINVAL" error for reasons even less well-understood... Fixes: https://github.com/nodejs/node/issues/16141 Fixes: https://github.com/nodejs/node/issues/16194 PR-URL: https://github.com/nodejs/node/pull/16225 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel Reviewed-By: Luigi Pinca Reviewed-By: Refael Ackermann Reviewed-By: Yuta Hiroto --- lib/internal/bootstrap_node.js | 2 +- test/pseudo-tty/pseudo-tty.status | 5 +++++ test/pseudo-tty/test-tty-stdout-resize.js | 11 +++++++++++ test/pseudo-tty/test-tty-stdout-resize.out | 0 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/pseudo-tty/test-tty-stdout-resize.js create mode 100644 test/pseudo-tty/test-tty-stdout-resize.out diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 1ab55a84459e79..48a4588543678e 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -29,6 +29,7 @@ const _process = NativeModule.require('internal/process'); _process.setupConfig(NativeModule._source); + _process.setupSignalHandlers(); NativeModule.require('internal/process/warning').setup(); NativeModule.require('internal/process/next_tick').setup(); NativeModule.require('internal/process/stdio').setup(); @@ -51,7 +52,6 @@ _process.setup_cpuUsage(); _process.setupMemoryUsage(); _process.setupKillAndExit(); - _process.setupSignalHandlers(); if (global.__coverage__) NativeModule.require('internal/process/write-coverage').setup(); diff --git a/test/pseudo-tty/pseudo-tty.status b/test/pseudo-tty/pseudo-tty.status index 13279019b6bd72..5c8114692d9447 100644 --- a/test/pseudo-tty/pseudo-tty.status +++ b/test/pseudo-tty/pseudo-tty.status @@ -3,3 +3,8 @@ prefix pseudo-tty [$system==aix] # being investigated under https://github.com/nodejs/node/issues/9728 test-tty-wrap : FAIL, PASS + +[$system==solaris] +# https://github.com/nodejs/node/pull/16225 - `ioctl(fd, TIOCGWINSZ)` seems +# to fail with EINVAL on SmartOS when `fd` is a pty from python's pty module. +test-tty-stdout-resize : FAIL, PASS diff --git a/test/pseudo-tty/test-tty-stdout-resize.js b/test/pseudo-tty/test-tty-stdout-resize.js new file mode 100644 index 00000000000000..c92db615020c78 --- /dev/null +++ b/test/pseudo-tty/test-tty-stdout-resize.js @@ -0,0 +1,11 @@ +'use strict'; +const { mustCall } = require('../common'); +const { notStrictEqual } = require('assert'); + +// tty.WriteStream#_refreshSize() only emits the 'resize' event when the +// window dimensions change. We cannot influence that from the script +// but we can set the old values to something exceedingly unlikely. +process.stdout.columns = 9001; +process.stdout.on('resize', mustCall()); +process.kill(process.pid, 'SIGWINCH'); +setImmediate(mustCall(() => notStrictEqual(process.stdout.columns, 9001))); diff --git a/test/pseudo-tty/test-tty-stdout-resize.out b/test/pseudo-tty/test-tty-stdout-resize.out new file mode 100644 index 00000000000000..e69de29bb2d1d6