Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

socket.remoteAddress after close is undefined #9287

Closed
jameshartig opened this issue Feb 26, 2015 · 3 comments
Closed

socket.remoteAddress after close is undefined #9287

jameshartig opened this issue Feb 26, 2015 · 3 comments

Comments

@jameshartig
Copy link

socket.remoteAddress after close is undefined because this._handle is null. Since we're caching this._peername can we just change _getpeername to return this._peername if it already exists and not always look for a this._handle.

Related stackoverflow posts:
http://stackoverflow.com/questions/12444598/why-is-socket-remoteaddress-undefined-on-end-event
http://stackoverflow.com/questions/12126403/getting-the-ip-address-of-a-socket-inside-a-close-event-handler

@jameshartig jameshartig changed the title socket.remoteAddress after close socket.remoteAddress after close is undefined Feb 26, 2015
@tjfontaine
Copy link

I would need to look back through some other issues, but in the past I've advocated for always caching the data, even though it could potentially result in a few more syscalls under the hood, it often leads to easier debugging experiences for everyone.

I would definitely entertain a PR that always caches the remote side for both inbound and outbound connections.

@jameshartig
Copy link
Author

@tjfontaine I just made a PR that hopefully does what you were looking for. It's caching the _peername once we get one. It's only removing it if connect is called again.

jameshartig pushed a commit to jameshartig/node that referenced this issue Mar 10, 2015
Allows socket.remote* properties to still be accessed even after the
socket is closed. Fixes nodejs#9287
cjihrig pushed a commit that referenced this issue Mar 16, 2015
Allows socket.remote* properties to still be accessed even after the
socket is closed.

Fixes: #9287
PR-URL: #9366
Reviewed-By: Colin Ihrig <[email protected]>
@tjfontaine tjfontaine self-assigned this Mar 16, 2015
@cjihrig
Copy link

cjihrig commented Mar 16, 2015

Closed in 8c38b07

@cjihrig cjihrig closed this as completed Mar 16, 2015
cjihrig pushed a commit to nodejs/node that referenced this issue Mar 16, 2015
Allows socket.remote* properties to still be accessed even after the
socket is closed.

Fixes: nodejs/node-v0.x-archive#9287
PR-URL: nodejs/node-v0.x-archive#9366
Reviewed-By: Colin Ihrig <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants