From 767321c174e34f4d541d1c3d8dbf08c9e16403d7 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Mon, 8 Apr 2019 18:00:09 +0200 Subject: [PATCH] net: inline maybeDestroy() `maybeDestroy()` is only called from the listener of the `'end'` event. That event is only emitted after the socket is connected (after `UV_EOF` is read) and after `socket.readable` is set to `false`. --- lib/net.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/net.js b/lib/net.js index 99d3fc2ed7b6bf..3f53bd4f167680 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(); }