Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dark mongoose magic: "Invalid argument to findOne"

We have several nodejs daemons that make use of mongoose while sharing the same persistence layer (shared module containing the queries).

In one of these daemons (always the same one) we randomly (few times a week) get the following error from mongoose:

mongoose: Invalid argument to findOne()

We've checked all queries and were not able to find out where this might come from. The errors call stack is different every time (no specific mongoose call seems to cause this issue) so we don't think this is specific to the business logic.

In order to do some debugging we added the following logging in case the error happens again:

log({
  // What mongoose checks (both false -> the error).
  isInstanceOfMQuery: conds instanceof mquery,
  isObject: mquery.utils.isObject(conds),
  // Trying to find out what this value is.
  conds,
  toString: Object.prototype.toString.call(conds)
  inspect: util.inspect(conds, { showHidden: true, depth: null, showProxy: true })
})

conds is the argument that mongoose is complaining about. log() will JSON.stringify() the whole thing.

This is one of the logs that resulted from this call:

{
  "isInstanceOfMQuery": false,
  "isObject": false,
  "conds": {},
  "toString": "[object Null]"
  "inspect": "{}",
}

Now this confuses me even more... how can conds be {} and null at the same time?!

Answers I'm looking for:

  • How can I reproduce this kind of object that conds contains?
  • How would you proceed with a bug that apparently happens randomly and seldomly?
  • Is there more we could log in order to identify what kind of value conds has or where it comes from?

Any ideas appreciated!

like image 295
patrickd Avatar asked Feb 22 '17 17:02

patrickd


1 Answers

This is probably a node bug with the PR to fix here. It's not yet included in a release.

It's not reliably reproducible since it seems to depend on pointers and v8's garbage collection. Just gotta wait for it to be fixed upstream.

like image 71
Sebmaster Avatar answered Oct 21 '22 03:10

Sebmaster