From 74451263a3cf38946060be81302afa8abc6f19be Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 10 Nov 2018 20:59:50 +0100 Subject: [PATCH] net: partially revert "simplify Socket.prototype._final" Partially revert b7e6ccd0cc60f20cc397e6ac0705bb3f38c7d225 because it broke a test that was added since its last CI run. Refs: https://github.com/nodejs/node/pull/24075 Refs: https://github.com/nodejs/node/pull/23866 PR-URL: https://github.com/nodejs/node/pull/24288 Reviewed-By: Colin Ihrig Reviewed-By: Ujjwal Sharma --- lib/net.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/net.js b/lib/net.js index ae389940b39596..1bcbe94c53ddb9 100644 --- a/lib/net.js +++ b/lib/net.js @@ -345,6 +345,12 @@ Socket.prototype._final = function(cb) { return this.once('connect', () => this._final(cb)); } + // TODO(addaleax): This should not be necessary. + if (!this.readable || this._readableState.ended) { + cb(); + return this.destroy(); + } + if (!this._handle) return cb();