diff --git a/lib/net.js b/lib/net.js index 86505a9a4510a5..d3b712ce9c18fa 100644 --- a/lib/net.js +++ b/lib/net.js @@ -541,19 +541,9 @@ function onReadableStreamEnd() { if (this.writable) this.end(); } - maybeDestroy(this); -} - -// Call whenever we set writable=false or readable=false -function maybeDestroy(socket) { - if (!socket.readable && - !socket.writable && - !socket.destroyed && - !socket.connecting && - !socket.writableLength) { - socket.destroy(); - } + if (!this.destroyed && !this.writable && !this.writableLength) + this.destroy(); }