diff options
author | OneNail <OneNail@yeah.net> | 2022-05-08 18:54:08 +0300 |
---|---|---|
committer | Bryan English <bryan@bryanenglish.com> | 2022-05-30 19:33:53 +0300 |
commit | 11c783fa63733a8cff9d983b233c04fac88359b3 (patch) | |
tree | ff40f3e42163bf713aa2d179637d2dfafab2e1bd /lib | |
parent | 7d8d9d625a513c25641dfff3bc526f261cbb253f (diff) |
net: remoteAddress always undefined called before connected
PR-URL: https://github.com/nodejs/node/pull/43011
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net.js | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/net.js b/lib/net.js index 1c98cf48201..4318beb501b 100644 --- a/lib/net.js +++ b/lib/net.js @@ -733,7 +733,7 @@ Socket.prototype._destroy = function(exception, cb) { }; Socket.prototype._getpeername = function() { - if (!this._handle || !this._handle.getpeername) { + if (!this._handle || !this._handle.getpeername || this.connecting) { return this._peername || {}; } else if (!this._peername) { this._peername = {}; @@ -760,7 +760,9 @@ protoGetter('remoteAddress', function remoteAddress() { }); protoGetter('remoteFamily', function remoteFamily() { - return `IPv${this._getpeername().family}`; + const { family } = this._getpeername(); + + return family ? `IPv${family}` : family; }); protoGetter('remotePort', function remotePort() { |