Error: connect ECONNRESET

I have an express server running on localhost through app.listen().
It serves images through app.get(‘imageId’). The images are read from a DB.
I have a client application firing 400+ requests at the same time through http.get()

After the first 300+ requests, I get this error on the client side for each subsequent request:
Error: connect ECONNRESET 127.0.0.1:8080
There is no stack or any further detail.

On the server side, I have these error handlers, but none of them print anything:

server.on('error', function(err){
    console.error('on error handler');
    console.error(err);
});
server.on('clientError', function(err){
    console.error('on clientError handler');
    console.error(err);
});
process.on('uncaughtException', function(err) {
    console.error('process.on handler');
    console.error(err);
});

My guess is that the server is not able to handle all the requests at once and it starts rejecting the connections until it frees resources, but haven’t found a way to prove it.

Is there a way to specify the number of connections on the server?
Am I doing something wrong on the server side to handle the error?

Author: Fantashit

2 thoughts on “Error: connect ECONNRESET

  1. Ugh, wish this were addressed somewhere. I’ve got unit tests randomly failing with ECONNRESET and the more functionality I add to the server, the higher frequency of the failures.

  2. I had this Error too and was able to solve it after days of debugging and analysis:

    my solution

    For me VirtualBox (for Docker) was the Problem. I had Port Forwarding configured on my VM and the error only occured on the forwarded port.

    general conclusions

    The following observations may save you days of work I had to invest:

    • For me the problem only occurred on connections from localhost to localhost on one port. -> check changing any of these constants solves the problem.
    • For me the problem only occurred on my machine -> let someone else try it.
    • For me the problem only occurred after a while and couldn’t be reproduced reliably
    • My Problem couldn’t be inspected with any of nodes or expresses (debug-)tools. -> don’t waste time on this

    -> figure out if something is messing around with your network (-settings), like VMs, Firewalls etc., this is probably the cause of the problem.

Comments are closed.