Sometimes request.ip returns undefined
See original GitHub issueAfter certain types of errors (e.g. { [Error: Parse Error] bytesParsed: 159, code: 'HPE_INVALID_METHOD' }
) the remote socket gets closed, and calling .remoteAddress
on it will return undefined
.
Because koa’s request.ip
is lazy, this means it’s sometimes returning undefined
which screws up some things (e.g. I record errors in a format that requires an ip, and would like to see the ip address of the bad requests).
I think this is quite unexpected behavior, and would be more sensible to strictly evaluate .ip
to always be available
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Client IP is sometimes undefined in a Nodejs app hosted in ...
I really don't know what that is and I'm doubting that whenever its making the request, the IP is returning undefined . UPDATE....
Read more >[@types/express-serve-static-core] Request.ip should be ...
So, after looking into it, the reason why req.ip can be undefined is because req.connection.remoteAddress is used as part of deriving req.ip ...
Read more >Client IP is sometimes undefined in a Nodejs app hosted in ...
I have rather an unusual problem with my app. The app heavily depends on the client's IP which is sometimes undefined .
Read more >$request->ip() undefined
I have two methods to which I pass Request object: Copy Code public function pull(Request $requestSvr) { if($requestSvr->user()->tokenCan('update')) ...
Read more >How to get a client IP Address in Node.js (6 ways)
Learn How to get a client IP Address using Node.js in 6 ... If they do not set XFF, the optional chaining operator...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m making a PR now, it’s almost done
I’d be in favor of caching the value. It could be set in
createContext
. The request IP shouldn’t be changing.