node-modules / agentkeepalive

Support keepalive http agent.
MIT License
579 stars 57 forks source link

Socket Hangup Issue #85

Open jAddict7 opened 4 years ago

jAddict7 commented 4 years ago

Dear Sir, Thanks for the awesome work. We have GPS server running Node JS, from where the co-ordinates are pushed to another server using HTTPS node module. Every second we need to send around 60-80 requests. Node JS is running out of memory, so on regular basis we restart the server. When we restart, requests are hanged for several hours and triggered only for every 5 seconds. And rest are hanged and not working. After some hours, it works fine even with high load of 80 requests per second.

const query = JSON.stringify({
    'device_id': XXX,
    'items': YYY,
});

const options = {
    hostname: 'HOST',
    port: 443,
    path: 'Page Link',
    method: 'POST',
    headers: {
        'Connection': 'keep-alive',
        'Content-Type': 'application/json',
        'Content-Length': query.length
    }
};

var request = https.request(options, (res) => {
    res.on('data', (data) => {
        console.log('Response Data :: '+data);
    }).on('end', () => {});
    res.on('error', (e) => {
        console.error('Response :: '+e);
    });
});

request.on('error', (e) => {
    console.error('Request :: '+e);
});
request.write(query);
request.end();

We request to the same URL. Is there any problem in the implementation? Will our module save us from the problem we are into? Please do guide us.