Node.js server stops responding
<p>I am working on node.js HTTPS requests. I have done enough research and checked all things as well but still I think I am missing something. 
What I want to achieve is, when someone sends HTTPS GET request to my URL, I have to send them one file in response so they can download. Everything works fine, I have implemented "FS", "HTTPS", and it writes in proper manner as well, but when I send bulk traffic on my URL after every 1000 requests on an average 40 requests gets failed. </p>

<p>I am not sure why is this happening, I have set this as well:</p>

<pre><code>var https = require('https');
https.globalAgent.maxSockets = Infinity;
</code></pre>

<p>Can anyone please help me to understand and resolve issue? 
Thanks in advance!</p>

<p>Anvesh</p>

<p><strong>EDIT</strong>: On request I am adding my code, I have removed few lines of code because of privacy. </p>

<pre><code>var https = require('https');
https.globalAgent.maxSockets = Infinity;
//var port = process.env.port || 1337;
fileSystem = require('fs'),
fileToWriteLog = require('fs'),
    path = require('path');
var mime = require('mime');
var cors = require('cors');


var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

var express = require('express'),
    app = module.exports.app = express();

app.use(cors());


// Created to use HTTPS
var options = {
    pfx: fileSystem.readFileSync('Certificate/key.pfx'),
    passphrase: 'XXX'   
};

var server = https.createServer(options,app);
var io = require('socket.io').listen(server);  //pass a https.Server instance
var port = 8080;
console.log(process.env.PORT);
server.listen(port,"0.0.0.0", function () {
    console.log("Secure Express server listening on port " + port);
});  //listen on port 8082

// routing

app.get('/stream/:patam1/:param2', function (request, response) {    
        var patam1 = request.param("patam1");
        var param2 = decodeURIComponent(request.param("param2"));


                var filePath = "XXXX" + param2;
                console.log(filePath);

                var stat = fileSystem.statSync(filePath);
                response.writeHead(200, {
                    'Content-Type': 'XXX', 
                    'Content-Length': stat.size
                });

                var readStream = fileSystem.createReadStream(filePath);
                readStream.on('data', function (data) {                                 
                    var flushed = response.write(data);
                    // Pause the read stream when the write stream gets saturated
                    if (!flushed)
                        readStream.pause();
                });
                response.on('drain', function () {                                  
                    // Resume the read stream when the write stream gets hungry 
                    readStream.resume();
                });
                // readStream.on('end', function () {                        
                     // response.end();
                // });          

});
</code></pre>