From ef43fc9d23c5b84cec226a978c91ed570a6f68e6 Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Mon, 9 May 2022 00:39:34 +0900 Subject: [PATCH] net: socket._getpeername Fixes: https://github.com/nodejs/node/issues/43009 If calling `this._handle.getpeername` returns an error at the first call, its result shouldn't be cached to `this._peername`. Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com --- lib/net.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/net.js b/lib/net.js index 1c98cf4820178f..f15a8eed10ef9c 100644 --- a/lib/net.js +++ b/lib/net.js @@ -736,9 +736,11 @@ Socket.prototype._getpeername = function() { if (!this._handle || !this._handle.getpeername) { return this._peername || {}; } else if (!this._peername) { - this._peername = {}; + const out = {}; + const err = this._handle.getpeername(out); // FIXME(bnoordhuis) Throw when the return value is not 0? - this._handle.getpeername(this._peername); + if (err) return {}; + this._peername = out; } return this._peername; };