Skip to content

Commit

Permalink
net: socket._getpeername
Browse files Browse the repository at this point in the history
Fixes: nodejs#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
  • Loading branch information
daeyeon committed May 8, 2022
1 parent be1ca70 commit ef43fc9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit ef43fc9

Please sign in to comment.