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?

Read more here: Source link