Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1293

db.collection catching application errors and calling the callback twice

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.0.2
    • Affects Version/s: 2.2.25, 2.2.34, 3.0.1
    • Component/s: None

      db.getCollection is catching our application errors and calling the callback we pass to it twice.

      We call db.collection has follows:

      db.collection(collectionName, callback);

      The callback then executes our application code (in the same tick). If we throw an error it is being caught by the code in db.collection which then calls the callback again which I believe is incorrect behaviour.

      I can see this was attempted to be fixed 8 months ago by @christkv but it looks like the line that actually makes the fix work is commented out:
      https://github.com/mongodb/node-mongodb-native/blame/2.2/lib/db.js#L466

      I've also noticed that a lot of the asynchronous methods in the mongo driver invoke handleCallback which introduces an asynchronous break to the code flow. Would that be an alternative fix for this issue?

            Assignee:
            jessica.lord Jessica Lord
            Reporter:
            leigh.jones@ripjar.com Leigh Jones
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: