Reputation: 471
I found our Node services intercommunication (using request) will occationally report this error:
Error: Parse Error
at socketOnEnd (_http_server.js:455:20)
at Socket.emit (events.js:203:15)
at Socket.EventEmitter.emit (domain.js:448:20)
at endReadableNT (_stream_readable.js:1129:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
After some digging in _http_server.js, it turns out to be the http parser finish error. It means that util the socket close, the http parser cant correctly parse the http request.
Our service log shows that its the client timeout and close the socket and then the server report this error. So I doubt that it's this request issue cause the problem, but I have no further evidence.
Another question is why the Node server receiving a bad http request not aborting the parse phase and response with an error immediately but hanging there until the client timeout and close the socket?
Is anyone reaching the same problem?
p.s.
Using Node version: 10.16.0
Upvotes: 2
Views: 1599
Reputation: 471
After logging the socket data, I found the malformed http request. It's missing the body:
POST /internals/topics/list HTTP/1.1\r\ncontent-type: application/json\r\nx-client-host: production/user-service-5d76d998d8-wr9ws\r\nHost: topic-service.prod:3000\r\naccept-encoding: gzip, deflate\r\naccept: application/json\r\ncontent-length: 117\r\nnewrelic:xxx\r\nConnection: close\r\n\r\n
So this really is a request package problem and it's not maintained anymore, I am going to use got package instead.
Hope it helpful for others who reach the same problem.
Upvotes: 2