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.

      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

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

              Created:
              Updated:
              Resolved:
              4 years, 9 weeks, 2 days ago