uptime icon indicating copy to clipboard operation
uptime copied to clipboard

TypeError: Cannot read property 'firstTested' of null

Open liqinshan opened this issue 10 years ago • 9 comments

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)

liqinshan avatar Nov 17 '14 05:11 liqinshan

have you ever added and removed tags from Checks?

LaurentDumont avatar Nov 17 '14 05:11 LaurentDumont

yes. that's the reason?

liqinshan avatar Nov 17 '14 05:11 liqinshan

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( {

LaurentDumont avatar Nov 17 '14 06:11 LaurentDumont

Thank you very much.

liqinshan avatar Nov 17 '14 06:11 liqinshan

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

caclifton avatar Nov 24 '14 20:11 caclifton

@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

liqinshan avatar Nov 25 '14 08:11 liqinshan

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)

ip2k avatar Dec 30 '14 00:12 ip2k

+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)

chaseconey avatar Feb 14 '15 00:02 chaseconey

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 }});

emslade avatar May 28 '15 10:05 emslade