fzaninotto / uptime

A remote monitoring application using Node.js, MongoDB, and Twitter Bootstrap.
http://fzaninotto.github.com/uptime/
MIT License
3.62k stars 703 forks source link

TypeError: Cannot read property 'firstTested' of null #279

Open liqinshan opened 10 years ago

liqinshan commented 10 years ago

I got an error:

/opt/app/uptime-master/node_modules/mongoose/lib/utils.js:413 throw err; ^ TypeError: Cannot read property 'firstTested' of null at IntervalBuilder.calculateDuration (/opt/app/uptime-master/lib/intervalBuilder.js:100:44) at Array.async.auto.duration as 3 at listener (/opt/app/uptime-master/node_modules/async/lib/async.js:412:46) at /opt/app/uptime-master/node_modules/async/lib/async.js:371:17 at Array.forEach (native) at _forEach (/opt/app/uptime-master/node_modules/async/lib/async.js:26:24) at taskComplete (/opt/app/uptime-master/node_modules/async/lib/async.js:370:13) at Promise.taskCallback (/opt/app/uptime-master/node_modules/async/lib/async.js:396:21) at Promise. (/opt/app/uptime-master/node_modules/mongoose/node_modules/mpromise/lib/promise.js:162:8) at Promise.emit (events.js:95:17)

LaurentDumont commented 10 years ago

have you ever added and removed tags from Checks?

liqinshan commented 10 years ago

yes. that's the reason?

LaurentDumont commented 10 years ago

Yep, I'm not well versed enough in the code, but something doesn't get deleted properly when you remove tags and there were active checks. It doesn't crash right away but I assume when it rotates to that part of the script, everything breaks.

Two "solutions" :

Remove any tags from MongoDB named after the checks you created. Re-create the tags on a dummy check.

Here are some of the very basic queries I had to use in order to remove any orphaned checks :

db.pings.find({ "tags" : { "$in" : ["Tag_name"] } }) db.pings.remove({ "tags" : { "$in" : ["Tag_name"] } })

You might need these also

db.tags.remove( { } ) db.tagdailystats.remove( { } ) db.taghourlystats.remove( { } ) db.tagmonthlystats.remove( { } ) db.tagyearlystats.remove( {

liqinshan commented 10 years ago

Thank you very much.

caclifton commented 10 years ago

@davechina , there is also a fix for this that can be applied to intervalbuilder.js, see https://github.com/fzaninotto/uptime/pull/246/files

liqinshan commented 10 years ago

@christisking, Thanks a lot. My uptime had been run for about 2 months, and suddenly crash. Some checks show down, but actually are up; and when the the monitor poll a check, it creates ping more than once. Still couldn't find out why. error

ip2k commented 9 years ago

I also just got this, and I wasn't removing tags (but I had been adding / removing checks with the same name / URIs if that matters):

ESC[0;36mMongoose:ESC[0m checkevents.find({ timestamp: { ESC[32m'$gt'ESC[39m: new Date("Mon, 29 Dec 2014 00:00:00 GMT"), ESC[32m'$lte'ESC[39m: new Date("Mon, 29 Dec 2014 23:59:59 GMT") }, check: { ESC[32m'$in'ESC[39m: [ ObjectId("549a26891a3a4b4669387a1f") ] } }) { fields: ESC[90mundefinedESC[39m, sort: { timestamp: ESC[33m1ESC[39m } }
ESC[0;36mMongoose:ESC[0m checks.findOne({ _id: ObjectId("54864339f7236e1074121ff9") }) { fields: ESC[90mundefinedESC[39m }
ESC[0;36mMongoose:ESC[0m checks.findOne({ _id: ObjectId("5482568f7f8265bc6d503a1d") }) { fields: ESC[90mundefinedESC[39m }
ESC[0;36mMongoose:ESC[0m checks.findOne({ _id: ObjectId("5482563a7f8265bc6d503a14") }) { fields: ESC[90mundefinedESC[39m }
ESC[0;36mMongoose:ESC[0m checks.findOne({ _id: ObjectId("548255a57f8265bc6d503a06") }) { fields: ESC[90mundefinedESC[39m }
ESC[0;36mMongoose:ESC[0m checks.findOne({ _id: ObjectId("5482529fe7e0df646ce174be") }) { fields: ESC[90mundefinedESC[39m }

/home/ubuntu/uptime/lib/intervalBuilder.js:100
  var durationBegin = Math.max(begin, check.firstTested),
                                           ^
TypeError: Cannot read property 'firstTested' of null
    at IntervalBuilder.calculateDuration (/home/ubuntu/uptime/lib/intervalBuilder.js:100:44)
    at Array.async.auto.duration [as 3] (/home/ubuntu/uptime/lib/intervalBuilder.js:48:14)
    at listener (/home/ubuntu/uptime/node_modules/async/lib/async.js:412:46)
    at /home/ubuntu/uptime/node_modules/async/lib/async.js:371:17
    at Array.forEach (native)
    at _forEach (/home/ubuntu/uptime/node_modules/async/lib/async.js:26:24)
    at taskComplete (/home/ubuntu/uptime/node_modules/async/lib/async.js:370:13)
    at Promise.taskCallback (/home/ubuntu/uptime/node_modules/async/lib/async.js:396:21)
    at Promise.<anonymous> (/home/ubuntu/uptime/node_modules/mongoose/node_modules/mpromise/lib/promise.js:177:8)
    at Promise.EventEmitter.emit (events.js:95:17)
chaseconey commented 9 years ago

+1 I am having this same issue.

    /srv/uptime/node_modules/mongoose/lib/utils.js:413
        throw err;
              ^
TypeError: Cannot read property 'firstTested' of null
    at IntervalBuilder.calculateDuration (/srv/uptime/lib/intervalBuilder.js:100:44)
    at Array.async.auto.duration [as 3] (/srv/uptime/lib/intervalBuilder.js:48:14)
    at listener (/srv/uptime/node_modules/async/lib/async.js:412:46)
    at /srv/uptime/node_modules/async/lib/async.js:371:17
    at Array.forEach (native)
    at _forEach (/srv/uptime/node_modules/async/lib/async.js:26:24)
    at taskComplete (/srv/uptime/node_modules/async/lib/async.js:370:13)
    at Promise.taskCallback (/srv/uptime/node_modules/async/lib/async.js:396:21)
    at Promise.<anonymous> (/srv/uptime/node_modules/mongoose/node_modules/mpromise/lib/promise.js:162:8)
    at Promise.emit (events.js:95:17)
emslade commented 9 years ago

I encountered the same issue after deleting a check.

I fixed it by running the following in mongo:

check_ids = db.checks.find({}, { _id: true }).toArray().map(function (check) { return check._id });
db.pings.remove({ check: { $nin: check_ids }});