I am creating a JsonClient with Restify, calling a web service, then Ctrl-X terminating the remote Json service..
The client dies hard EVEN with error handling:
events.js:72
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at errnoException (net.js:901:11)
at TCP.onread (net.js:556:19)
Here's the simple program I am using:
var client = restify.createJsonClient({
url: "http://localhost:5653",
version: '*'
});
client.on("error", function (err) {
console.log("ssss" + err);
});
client.get("/program/state", function (err) {
console.log("gett");
});
The problem isn't with an error during the call, only much later.. seemingly when the client is idle..
Same here, the error occurs when the JsonClient is idle. Did you fixed it anyway?
I solved it:
By default NodeJS uses agents to keep the TCP connection open, so you can reuse it.
The problem is that if the server is closed, or it closes your connection for whatever reason you get the ECONNRESET error.
To close the connection every time you just need to set agent: false in your client creation:
var client = restify.createJsonClient({
url: "http://localhost:5653",
version: '*',
agent: false
});
It worked for me, I hope it helps you too.
That is awesome news.. I will look more into this.
Maybe a good idea would be to put this in the official documentation on
JsonClient behavior?
This is almost certainly not what you want - that option will cause you to
thrash sockets under load.
Can you guys try just doing:
client.on('error', function (err) {
console.error('I would have blown up: ' + err.toString());
});
On Thu, Jan 30, 2014 at 11:39 AM, Analogreality [email protected]:
That is awesome news.. I will look more into this.
Maybe a good idea would be to put this in the official documentation on
JsonClient behavior?
Reply to this email directly or view it on GitHubhttps://github.com/mcavage/node-restify/issues/485#issuecomment-33712147
.
I get this error using the StringClient!
Code that was working fine before not gets an error using restify 2.6.0
events.js:72
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at errnoException (net.js:901:11)
at TCP.onread (net.js:556:19)
The "agent: false" setting seems to fix the problem, but I have no idea what side effects it may cause!
Restify is still awesome by the way :-)
I have the same problem. The service I call trash the connection for a reason I don't really know. An ECONNRESET error is sent from NodeJS which the server crash even with server.on('uncaughtException', (req, res, route, error) => {..}).
I have added client.on('error', function (err) { ... });
But It doesn't get through.
Only the agent : false solved this problem.
I'm using Restify 4.0.3
Is it normal ?
Most helpful comment
I solved it:
By default NodeJS uses agents to keep the TCP connection open, so you can reuse it.
The problem is that if the server is closed, or it closes your connection for whatever reason you get the ECONNRESET error.
To close the connection every time you just need to set
agent: falsein your client creation:It worked for me, I hope it helps you too.