-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 1.3, 1.4
-
Component/s: None
-
Labels:
-
Empty show more show less
The following code, which exists in lib/mongodb/collection.js on 1.3.19 and in lib/mongodb/collection/core.js on 1.4.x:
this.db._executeUpdateCommand(updateCommand, commandOptions, function (err, error) { error = error && error.documents; if(!callback) return; if(err) { callback(err); } else if(error[0].err || error[0].errmsg) { callback(utils.toError(error[0])); } else { // Perform the callback callback(null, error[0].n, error[0]); } });
As you can see, the code assumes that 'error.documents' always exists, and does not handle the case where it is null. This occurs infrequently, and I have not yet identified the potential root cause. The same code (or very similar variations of it) is duplicated across a few functions, all of which are potentially exposed to the same issue.
The stack trace, from 1.3.19:
events.js:72 throw er; // Unhandled 'error' event ^ TypeError: Cannot read property '0' of null at null.<anonymous> (/app/node_modules/mongodb/lib/mongodb/collection.js:493:22) at g (events.js:175:14) at EventEmitter.emit (events.js:98:17) at Base.__executeAllServerSpecificErrorCallbacks (/app/node_modules/mongodb/lib/mongodb/connection/base.js:315:29) at /app/node_modules/mongodb/lib/mongodb/connection/repl_set/ha.js:273:22 at /app/node_modules/mongodb/lib/mongodb/connection/repl_set/ha.js:370:11 at /app/node_modules/mongodb/lib/mongodb/connection/repl_set/ha.js:352:28 at _callback (/app/node_modules/mongodb/lib/mongodb/db.js:670:5) at /app/node_modules/mongodb/lib/mongodb/auth/mongodb_cr.js:47:13 at /app/node_modules/mongodb/lib/mongodb/db.js:1670:9 at Server.Base._callHandler (/app/node_modules/mongodb/lib/mongodb/connection/base.js:382:41) at /app/node_modules/mongodb/lib/mongodb/connection/server.js:472:18 at MongoReply.parseBody (/app/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5) at null.<anonymous> (/app/node_modules/mongodb/lib/mongodb/connection/server.js:430:20) at EventEmitter.emit (events.js:95:17) at null.<anonymous> (/app/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:191:13) at EventEmitter.emit (events.js:98:17) at Socket.<anonymous> (/app/node_modules/mongodb/lib/mongodb/connection/connection.js:384:22) at Socket.EventEmitter.emit (events.js:95:17)