Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-11255

Document that 3.6 implicit sessions may cause noTimeout cursors to close while in use.

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: drivers, Server
    • Labels:
      None

      Description

      The following code will work on MongoDB 3.4. The cursor is created with the no timeout option and is left open on the server until the application closes it.

      for doc in coll.find(no_cursor_timeout=True):
          # Process document for longer than the default server
          # session timeout of 30 minutes.
          time.sleep(50 * 60)
      

      MongoDB 3.6 drivers will add an implicit session to every command. The find command will use a new session and again create a cursor with the no timeout option. However, that session will timeout after 30 minutes of inactivity and the cursor will be closed.

      Users that need the cursor timeout to exceed the session timeout will need to write code to periodically refresh the session. This will prevent the session (and cursor) from timing out:

      with client.start_session() as session:
          for doc in coll.find(no_cursor_timeout=True, session=session):
              # Process document for longer than the default server
              # session timeout of 30 minutes.
              for _ in range(10):
                  time.sleep(5 * 60)
                  # Periodically refresh the session to keep it and the cursor alive.
                  client.admin.command(
                      'refreshSessions', [session.session_id], session=session)
      

      I don't think this change has been documented yet. CC Alyson Cabral

      Scope

      • Update noCursorTimeout to include the session refresh requirements (e.g. implicit 30 minute max)
      • Update Mongo.startSession() and startSession to include the session timeout limit (30 minutes) + refreshSession
      • Add the Session.refreshSession() shell method if it exists. Otherwise point to refreshSession dbcommand
      • Update find/agg behavior sections to call out 30 minute session timeout behavior
      • Add to Cursor.tailable, tailable pages

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ravind.kumar Ravind Kumar (Inactive)
              Reporter:
              shane.harvey Shane Harvey
              Participants:
              Last commenter:
              Ravind Kumar Ravind Kumar (Inactive)
              Votes:
              2 Vote for this issue
              Watchers:
              11 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since reply:
                1 year, 6 weeks, 5 days ago
                Date of 1st Reply: