nodejs XHR calls stop after around 50 calls

I'm using the XHR nodejs module to do a lot of ajax calls (around a 100 now). I do this async using deferred. This works really well until the amount of requests passes somewhere around the 40 to 50 calls. Then it simply stops and does nothing indefinably. If I do in in sync(which isn't really an option) it does support all the calls i can through at it. So what it causing this problem?

My code is as followed:

    function getFile(url) {
        var def = deferred()
        ,xhr = new XMLHttpRequest(); 

        xhr.open("GET", url); 
        xhr.onreadystatechange = handler;
        //Callback
        function handler (){
            // If status is ready
            if (this.readyState == 4 && this.status >= 200 && this.status < 300 || this.status === 304) {
                try {
                    var result = eval(this.responseText);
                } catch (e) {
                    def.resolve(e);
                }
                def.resolve(result && result[0]);
            } else if (this.status === 401){
                console.log('Error 401')
                def.resolve(new Error('Error:' + this.responseText));
            };
        };
        xhr.send(null);
        return def.promise;
    };

If I console.log the status I keep getting a nice status 200.

I'm calling the getfile() with the following code snippet:

var express = require('express')
, app = express()
, fs = require('fs')
, XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest
, promisify = require('deferred').promisify
, deferred = require('deferred')
, readdir = promisify(fs.readdir)
, exists = promisify(fs.exists)
, writeFile = promisify(fs.writeFile)
, filepath = './public/movies/config/moviefiles.js'

    // Set max of events to unlimited
    req.setMaxListeners(0)
    readdir(configfileResults.moviepath).map(function (file) {
        var filename = file
        , year = longregex
        , movietitle = verylongregex
        if (year == null) year = ''
        var url = "http://api.themoviedb.org/2.1/Movie.search/"+configfileResults.language+"/json/apikey/"+movieTitle+"?year="+ year +"?="
        return getFile(url)(function (ajaxResult) {
            return {
                movieTitle:movieTitle,
                filename: file,
                movieScraperInfo: ajaxResult
            };
        });
    })(function (data) {
       return writeFile(filepath, JSON.stringify(data, null, 4));
    }).end(function () {
        // Download Cache
        downloadCache()
    }, function (e) {
        console.log("Failed", e);
    });

Thanks a lot!

EDIT:

As Brad suggested I added a lot of console logs.

function getFile(url) {
    var def = deferred()
    ,xhr = new XMLHttpRequest(); 
    console.log("url:", url);
        xhr.onreadystatechange = function() {
            console.log("status ready");
            if (this.readyState == 4 && this.status >= 200 && this.status < 300 || this.status === 304) {
                try {
                    var result = eval(this.responseText);
                    console.log('getting files', i++)
                } catch (e) {
                    def.resolve(e);
                }
                console.log("resolving files");
                def.resolve(result && result[0]);
            } else if (this.status === 401){
                console.log('Error 401')
                def.resolve(new Error('Error:' + this.responseText));
            };
            console.log("not ready");
        };
        console.log("out of callback");
    xhr.open("GET", url); 
    xhr.send(null);
    return def.promise;
};

The result:

I get 60 "url:", url logs showing all the urls needed to get the data. Then, the callback is being executed.

resulting in:

getting files 3 resolving files not ready status ready not ready status ready not ready status ready getting files 4 resolving files not ready status ready not ready status ready not ready status ready getting files 5 resolving files not ready status ready not ready status ready not ready status ready getting files 6 resolving files not ready status ready not ready status ready not ready status ready getting files 7 resolving files not ready status ready not ready status ready not ready status ready getting files 8 resolving files not ready status ready not ready status ready not ready status ready getting files 9 resolving files not ready status ready not ready status ready not ready status ready getting files 10 resolving files not ready status ready not ready status ready not ready status ready getting files 11 resolving files not ready status ready not ready status ready not ready status ready getting files 12 resolving files not ready status ready not ready status ready not ready status ready getting files 13 resolving files not ready status ready not ready status ready not ready status ready getting files 14 resolving files not ready status ready not ready status ready not ready status ready getting files 15 resolving files not ready status ready not ready status ready not ready status ready getting files 16 resolving files not ready status ready not ready status ready not ready status ready getting files 17 resolving files not ready status ready not ready status ready not ready status ready getting files 18 resolving files not ready status ready not ready status ready not ready status ready getting files 19 resolving files not ready status ready not ready status ready not ready status ready getting files 20 resolving files not ready status ready not ready status ready not ready status ready getting files 21 resolving files not ready status ready not ready status ready not ready status ready getting files 22 resolving files not ready status ready not ready status ready not ready status ready getting files 23 resolving files not ready status ready not ready status ready not ready status ready getting files 24 resolving files not ready status ready not ready status ready not ready status ready getting files 25 resolving files not ready status ready not ready status ready not ready status ready getting files 26 resolving files not ready status ready not ready status ready not ready status ready getting files 27 resolving files not ready status ready not ready status ready not ready status ready getting files 28 resolving files not ready status ready not ready status ready not ready status ready getting files 29 resolving files not ready status ready not ready status ready not ready status ready getting files 30 resolving files not ready status ready not ready status ready not ready status ready getting files 31 resolving files not ready status ready not ready status ready not ready status ready getting files 32 resolving files not ready status ready not ready status ready not ready status ready getting files 33 resolving files not ready status ready not ready status ready not ready status ready getting files 34 resolving files not ready status ready not ready status ready not ready status ready getting files 35 resolving files not ready status ready not ready status ready not ready status ready getting files 36 resolving files not ready status ready not ready status ready not ready status ready getting files 37 resolving files not ready status ready not ready status ready not ready status ready getting files 38 resolving files not ready status ready not ready status ready not ready status ready getting files 39 resolving files not ready status ready not ready status ready not ready status ready getting files 40 resolving files not ready

Ending in de 'not ready'.

Can anyone shed a light on this? See the code on github:

https://github.com/jansmolders86/mediacenterjs/blob/master/apps/movies/index.js

I figured out what the problem was. I was doing to much at the same time, keeping data in the memory while passing it on to other functions. In other words, I simply ran out of memory. I'm going o refactor the code.

Your syntax doesn't make sense. Can you clarify what is going on here?

return getFile(url)(function (ajaxResult) {
        return {
            movieTitle:movieTitle,
            filename: file,
            movieScraperInfo: ajaxResult
        };
    });