4

I have an app running which is doing every 20 to 30 minutes a http.request. When I do these requests every 10 seconds or so, it works just fine, but when there is a gap of 30 minutes between the requests, I get the following error message.

{ [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

Now I think, this is a timeout error. The connection dies in the background and when the next request take place, it throws this error since the connection is dead.

My idea now is to close the connection after each request and re-establisch the connection on every new request. But I have no idea how to accomplish this in NodeJS.

UPDATE

I found out that the problem appears, when I first GET than POST and again GET.

Here ist the code for GET and POST

https.request({ method: 'GET'..., function(res) {

}).on('error', function(e) {
    throw 'error';
}).end();

var request = https.request({ method: 'POST'..., function(res) {

}).on('error', function(e) {
    throw 'error';
});

request.write(query);
request.end();
Aley
  • 8,540
  • 7
  • 43
  • 56
  • If you are having a time out error. (as you have mentioned this), then I would suggest you first fix that. I.e. Fix the issue rather than looking at working around it. – Don Nov 19 '15 at 21:50
  • How do I do this? Will it help to increase timeout limit? What will happen, when the other server closes the connection? – Aley Nov 19 '15 at 21:53
  • Why is the server timing out. You need to find out what is taking a long time to execute on the server. – Don Nov 20 '15 at 00:04
  • Are you on windows server? If so which version? – user3658423 Nov 20 '15 at 00:13
  • Okay guys, found my mistake. The http option object was shared between requests and was obviously overwritten. – Aley Nov 20 '15 at 13:18
  • 2
    @Aley can you elaborate more on the solution? – kushdilip Oct 06 '16 at 06:57

0 Answers0