Skip to content

Commit

Permalink
net: do not call uv_shutdown if it did not start as writable
Browse files Browse the repository at this point in the history
Fixes: nodejs#22814.
  • Loading branch information
mcollina committed Sep 17, 2018
1 parent 1747d70 commit b30b568
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const {
} = errors.codes;
const { validateInt32, validateString } = require('internal/validators');
const kLastWriteQueueSize = Symbol('lastWriteQueueSize');
const kShouldShutdown = Symbol('shouldShutdown');

// Lazy loaded to improve startup performance.
let cluster;
Expand Down Expand Up @@ -245,6 +246,10 @@ function Socket(options) {
options.writable = options.writable || false;
const { allowHalfOpen } = options;

// Needed to avoid to call uv_shutdown during _final
// as otherwise it would error with an ENOTCONN.
this[kShouldShutdown] = options.writable;

// Prevent the "no-half-open enforcer" from being inherited from `Duplex`.
options.allowHalfOpen = true;
// For backwards compat do not emit close on destroy.
Expand Down Expand Up @@ -359,7 +364,7 @@ Socket.prototype._final = function(cb) {
debug('_final: not ended, call shutdown()');

// otherwise, just shutdown, or destroy() if not possible
if (!this._handle || !this._handle.shutdown) {
if (!this[kShouldShutdown] || !this._handle || !this._handle.shutdown) {
cb();
return this.destroy();
}
Expand Down
1 change: 1 addition & 0 deletions lib/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function ReadStream(fd, options) {
}
inherits(ReadStream, net.Socket);


ReadStream.prototype.setRawMode = function(flag) {
flag = !!flag;
this._handle.setRawMode(flag);
Expand Down
8 changes: 8 additions & 0 deletions test/pseudo-tty/test-tty-stdin-call-end.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

require('../common');

// This tests verifies that process.stdin.end() does not
// crash the process with ENOTCONN

process.stdin.end();
Empty file.

0 comments on commit b30b568

Please sign in to comment.