diff --git a/lib/net.js b/lib/net.js index 9a055c74bcc293..774de732990a24 100644 --- a/lib/net.js +++ b/lib/net.js @@ -207,10 +207,11 @@ function Socket(options) { this[kLastWriteQueueSize] = 0; if (typeof options === 'number') - options = { fd: options }; // Legacy interface. - else if (options === undefined) - options = {}; + options = { allowHalfOpen: false, fd: options }; // Legacy interface. + else + options = util._extend({}, options); + options.allowHalfOpen = Boolean(options.allowHalfOpen); stream.Duplex.call(this, options); if (options.handle) { @@ -236,8 +237,6 @@ function Socket(options) { this._writev = null; this._write = makeSyncWrite(fd); } - this.readable = options.readable !== false; - this.writable = options.writable !== false; } else { // these will be set once there is a connection this.readable = this.writable = false; @@ -255,9 +254,6 @@ function Socket(options) { // handle strings directly this._writableState.decodeStrings = false; - // default to *not* allowing half open sockets - this.allowHalfOpen = options && options.allowHalfOpen || false; - // if we have a handle, then start the flow of data into the // buffer. if not, then this will happen when we connect if (this._handle && options.readable !== false) { diff --git a/test/parallel/test-child-process-stdout-stderr-finish.js b/test/parallel/test-child-process-stdout-stderr-finish.js new file mode 100644 index 00000000000000..eba03d42c07bda --- /dev/null +++ b/test/parallel/test-child-process-stdout-stderr-finish.js @@ -0,0 +1,19 @@ +'use strict'; +const { mustCall } = require('../common'); +const { path } = require('../common/fixtures'); + +// This test ensures that the `'finish'` event is emitted on the child process's +// `stdout` and `stderr` when using `child_process.spawn()`. +// This is a regression test for https://github.com/nodejs/node/issues/19764. + +const { spawn } = require('child_process'); + +const child = spawn(process.argv[0], [path('print-chars.js'), 10]); + +child.stdout.on('finish', mustCall()); +child.stdout.on('end', mustCall()); +child.stdout.resume(); + +child.stderr.on('finish', mustCall()); +child.stderr.on('end', mustCall()); +child.stderr.resume();