Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-38388

Reuse of ended session causes error when used again during logical sessions cache reaping

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.0.5, 4.1.3, 4.1.5
    • Component/s: Sharding
    • None
    • ALL
    • Sharding 2018-12-17, Sharding 2018-12-31, Sharding 2019-01-14, Sharding 2019-01-28, Sharding 2019-02-11

      A user provided the following repro:

      const url = 'mongodb://localhost:31000/test?replicaSet=rs';
      
      MongoClient.connect(url, (err, client) => {
        if (err) return console.dir(err);
      
        let db = client.db();
        let cursor = db.collection('test').find({});
        let time = new Date().getTime();
        cursor.count((err, result) => {
          let stream = client.db().collection('test').watch([], { fullDocument: 'updateLookup' });
          console.log('watching...');
          stream.on('change', change => console.dir(change));
          stream.on('error', err => {
            let errTime = new Date().getTime();
            console.log(`error occured at: ${(new Date()).toISOString()}, in: ${errTime - time}ms`);
            console.dir(err);
            client.close();
          });
        });
      });
      

      Which would result in a cursor id XXXX not found error after ~3min in most runs.

      After investigation it appears what is happening is that the node driver creates an implicit session for the initial count command, sends an endSessions for that session after the command completes, then reuses that same session for the following aggregate and getMore commands. The error occurs when the session is used on a getMore during the session reaping process, which is more easily accomplished when using a tailable cursor given the regularity of getMore s sent to the server.

            Assignee:
            blake.oler@mongodb.com Blake Oler
            Reporter:
            matt.broadstone@mongodb.com Matt Broadstone
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: