1

In my node app I'm often making requests to a remote site. After I have done this 5 times, this stops working. I never get any 'data' or 'end' events from subsequent requests.

I came across this question which describes my problem precisely: node.js http.get hangs after 5 requests to remote site

I do not want to increase the maximum of 5 concurrent requests, because I never make 5 concurrent requests. I make them one at a time, but it seems these requests never end so they are never removed from the pool. Increasing the pool size wouldn't be a real solution.

I do consume the data as the given answer says. Here is my code:

function loadJSON(options, callback) {  
    var request = http.request(options, function(response) {  
        var receivedData = '';  
        response.on('data', function(data) {
            receivedData += data;
        });

        response.on('end', function() {
            console.log('end');
            var object = JSON.parse(receivedData);
            callback(null, object);
        });

        response.on('error', callback);
    });

    request.on('error', callback);
    request.end();
}
Community
  • 1
  • 1
Rits
  • 5,105
  • 4
  • 42
  • 53

0 Answers0