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; };