I found the problem by writing a script to record every request and then replay them.
The problem was caused because I had a callback that was not being returned.
myAsncFunc(function(err, data) {
if (err) { callback(err) }
//node kept going after the error was returned to the user.
// make sure you, return callback(err)
})
Here was my replay.js code for anyone interested.
var request = require('request');
var async = require('async');
var redis = require('redis');
var host = 'http://myhost.com';
var jobs = true;
var client = redis.createClient();
async.whilst(
function () { return jobs; },
function (callback) {
client.lpop('history', function(err, url) {
console.log(url);
if (!url) {
jobs = false;
callback();
}
request.get({url:host+url}, function() {
callback();
});
})
},
function (err) {
console.log('done')
}
);
And in you're express app.
app.get('/*', function(req, res, next) {
var url = req.originalUrl;
redis.rpush('history', url);
next();
});
It's cool because every history item that is played will be added again to the queue so it continually loops and every time you visit a new page, it will add that one to the queue.