Nodejs Socket hang up & ECONNRESET - HTTP post request from Meteor to Node js server
Considering the ECONNRESET error usually occurs when the *other side of the TCP connection
is closed abruptly.
- In case of your applicationit may be due to the
overloading
of the server and simply kills the connection as a return which in the similar way blocks the connection to yourmeteor server
To get more info about the error as mentioned in this thread.To handle the error you must use an event listener
to it to show the full stack traces
of it
As mentioned in this thread by Farid Nouri Neshat
To have one listener for a group of calls you can use domains and also catch other errors on runtime. Make sure each async operation related to http(Server/Client) is in different domain context comparing to the other parts of the code, the domain will automatically listen to the error events and will propagate it to it's own handler. So you only listen to that handler and get the error data.
but since the domain have already been deprecated you should use clusters as mentioned here in the docs which uses server.listen(message)
and the server.listen(handle)
or you can also use NODE_DEBUG=net
or use strace
Update
For the server disconnect i think the error might be in your handling of the bodyparser
.For a bad json
file the error is uncaught.
Node's default action following an uncaught exception is to exit(crash) on the process.
Handling of bodyparser for a json file can be done in the following way.
var parseJson = bodyPaser.json();app.use(function (req, res, next) { req.getBody = function (callback) { parseJson(req, res,function (err) { callback(err, req.body); }); }; next();});
Reference taken from the GITHUB open issue's here
Update 2
Basically the socket hangup
means that the socket doesn't end the connection within the specified time period
According to the source you can see that it occurs if the server never sends the response
.This error should be caught and handled by either
- retrying to the request.
- handling it later by setting more
time period
or putres.end()
at the end of your function to end the connection. - or you can use the
[http.get()][8]
with theget
requests which will automatically call thereq.end()
function
Hope it might help you a bit! Cheers!
Ok I found the issue myself here. Its in the node server code. I put return in a switch statement which is not a valid way to return a response in express, so I just removed the return from:
Before:
switch (callType) { case 'systemPushNotifications': return pushNotificationClass.sendPushNotificationsV2(response); break;}
Now:
switch (callType) { case 'systemPushNotifications': pushNotificationClass.sendPushNotificationsV2(response); break;}
The above return
was terminating the code before the: res.send("OK");