Skip to content

Commit b30b568

Browse files
committed
net: do not call uv_shutdown if it did not start as writable
Fixes: #22814.
1 parent 1747d70 commit b30b568

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

lib/net.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const {
8080
} = errors.codes;
8181
const { validateInt32, validateString } = require('internal/validators');
8282
const kLastWriteQueueSize = Symbol('lastWriteQueueSize');
83+
const kShouldShutdown = Symbol('shouldShutdown');
8384

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

249+
// Needed to avoid to call uv_shutdown during _final
250+
// as otherwise it would error with an ENOTCONN.
251+
this[kShouldShutdown] = options.writable;
252+
248253
// Prevent the "no-half-open enforcer" from being inherited from `Duplex`.
249254
options.allowHalfOpen = true;
250255
// For backwards compat do not emit close on destroy.
@@ -359,7 +364,7 @@ Socket.prototype._final = function(cb) {
359364
debug('_final: not ended, call shutdown()');
360365

361366
// otherwise, just shutdown, or destroy() if not possible
362-
if (!this._handle || !this._handle.shutdown) {
367+
if (!this[kShouldShutdown] || !this._handle || !this._handle.shutdown) {
363368
cb();
364369
return this.destroy();
365370
}

lib/tty.js

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function ReadStream(fd, options) {
6666
}
6767
inherits(ReadStream, net.Socket);
6868

69+
6970
ReadStream.prototype.setRawMode = function(flag) {
7071
flag = !!flag;
7172
this._handle.setRawMode(flag);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
// This tests verifies that process.stdin.end() does not
6+
// crash the process with ENOTCONN
7+
8+
process.stdin.end();

test/pseudo-tty/test-tty-stdin-call-end.out

Whitespace-only changes.

0 commit comments

Comments
 (0)