forwarded icon indicating copy to clipboard operation
forwarded copied to clipboard

getSocketAddr returned undefined, when the socket is disconnected

Open Shonke opened this issue 3 years ago • 6 comments

https://github.com/jshttp/forwarded/blob/master/index.js#L46

image image

Shonke avatar May 16 '22 15:05 Shonke

Hello, and thank you for the report. This is the API from Node.js; if you are trying to report this as a bug, you will need to report to Node.js, but if you are trying to report it as a bug to this module, please help us by providing what API should be used instead, thank you!

dougwilson avatar May 16 '22 15:05 dougwilson

Hello, and thank you for the report. This is the API from Node.js; if you are trying to report this as a bug, you will need to report to Node.js, but if you are trying to report it as a bug to this module, please help us by providing what API should be used instead, thank you!

For nodejs, this is not a bug: "Value may be undefined if the socket is destroyed" https://nodejs.org/dist/latest-v16.x/docs/api/net.html#socketremoteaddress

Shonke avatar May 17 '22 00:05 Shonke

undefined can cause unexpected damage, and it is described as string[] in types https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/forwarded/index.d.ts#L11

Shonke avatar May 17 '22 00:05 Shonke

For nodejs, this is not a bug: "Value may be undefined if the socket is destroyed"

Gotcha. So then what is the issue about?

dougwilson avatar May 17 '22 00:05 dougwilson

undefined can cause unexpected damage, and it is described as string[] in types

I'm not sure what this means. If you are saying there is an issue with the typings, you'll need to open an issue on the definatelytyped repo.

dougwilson avatar May 17 '22 00:05 dougwilson

@dougwilson getSocketAddr have problem because req.socket can be null. this code makes below TypeError

.../forwarded/index.js:49
    : req.connection.remoteAddress
                     ^
TypeError: Cannot read properties of null (reading 'remoteAddress')

fyi) https://nodejs.org/dist/latest-v16.x/docs/api/http.html#messagesocket

... or internally nulled

YangJonghun avatar Sep 27 '22 17:09 YangJonghun