Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-1602

Automate session refresh for long-lived cursors

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Component/s: Sessions
    • Labels:
      None
    • Needed

      The following code will throw an error when using the node driver:

      const cursor = coll.find();
      while (await cursor.hasNext()) {
        const doc = await cursor.next();
        await processDocForAnAccidentallyLongTime(doc);
      } 

      The reason is that the implicit session created when executing the initial find query controls the lifetime of the resulting cursor, and that session is automatically cleaned up after the logicalSessionsTimeoutMinutes (30 by default). When the user enters the second loop in the above example, they are confronted with an unhelpful "cursor id 124353857892752 does not exist" and then need to go learn a lot about how sessions work in MongoDB (they probably didn't even know an implicit session was created for them in the first place).

      SPEC-1268 proposed that we add new drivers API for users to explicitly refresh their long-lived sessions, but this ticket proposes that we periodically send refreshSessions internally for active, long-lived cursors.

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.broadstone@mongodb.com Matt Broadstone
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: