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

Node process crashes when bulk.exec is called

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.11
    • Affects Version/s: Not Applicable
    • Component/s: None

      /home/jenkins/resourceMgr_source/ResourceManagerNode/node_modules/mongodb/lib/utils.js:132
            throw err;
            ^TypeError: Cannot convert undefined or null to object
          at session.endSession (/home/jenkins/resourceMgr_source/ResourceManagerNode/node_modules/mongodb/lib/utils.js:398:11)    at ClientSession.endSession (/home/jenkins/resourceMgr_source/ResourceManagerNode/node_modules/mongodb-core/lib/sessions.js:129:41)
          at executeCallback (/home/jenkins/resourceMgr_source/ResourceManagerNode/node_modules/mongodb/lib/utils.js:397:17)
          at handleCallback (/home/jenkins/resourceMgr_source/ResourceManagerNode/node_modules/mongodb/lib/utils.js:128:55)
          at executeCommands (/home/jenkins/resourceMgr_source/ResourceManagerNode/node_modules/mongodb/lib/bulk/ordered.js:134:12)
          at /home/jenkins/resourceMgr_source/ResourceManagerNode/node_modules/mongodb/lib/utils.js:437:24
          at new Promise (<anonymous>)
          at executeOperation (/home/jenkins/resourceMgr_source/ResourceManagerNode/node_modules/mongodb/lib/utils.js:432:10)
          at OrderedBulkOperation.execute (/home/jenkins/resourceMgr_source/ResourceManagerNode/node_modules/mongodb/lib/bulk/ordered.js:121:12)    at router.put (/home/jenkins/resourceMgr_source/ResourceManagerNode/routes/resourcePools.js:132:16)
      

      This issue I have has never occurred before (this application has been running for a long time), however the express route that has the code is rarely used.

       

      I'm guessing there may be a conflict with transactions and the bulk operation? Maybe something else wasn't set right after a transaction ran? Not really sure what's going on here. In the server logs, there were no other requests running before for a good amount of time (at least a minute).

       

      I can't reproduce the issue either but I will provide the express route that is referenced in the backtrace.

       

      route that causes crash:

      router.put('/:resourcePool/', async (req, res) => {
        const db = req.db;
        const body = req.body;
        const poolsCollection = db.collection('resourcePools');
        const resources = db.collection('resources');
        const name = req.params.resourcePool;
        if (!body.name) {
          return fail(res, 'New name not specified.');
        }
        const pool = await poolsCollection.findOneAndUpdate({ name }, { $set: { name: body.name } });
        const assigned = pool.value.assignedResources;  const bulk = resources.initializeOrderedBulkOp();
        for (let i = 0; i < assigned.length; i += 1) {
          // Assigned resource
          const aResource = assigned[i];
          bulk.find({ _id: aResource }).updateOne({ $pull: { assignedResourcePools: name } });
          bulk.find({ _id: aResource }).updateOne({ $addToSet: { assignedResourcePools: body.name } });
        }
      //  console.log(bulk);
        try {
          await bulk.execute(); // <-- this is line 132 that causes the crash
        } catch (e) {
          logger.RMLog.info('ResourcePool name changed - but no dependent resources found in DB');
          socketserver.refreshPools();
          return succeed(res);
        }
        socketserver.refreshPools();
        console.log(res);
        return succeed(res);
      });
      

            Assignee:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Reporter:
            tang0001 Kenny Tang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: