-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Labels:None
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
- is duplicated by
-
DOCS-13011 noCursorTimeout can actually expire
- Closed
-
PYTHON-1879 no_cursor_timeout not functioning as expected
- Closed
- is related to
-
RUBY-3028 Document how to iterate cursor keeping session alive
- Backlog
-
PYTHON-1880 Raise a warning when no_cursor_timeout is used with an implicit session
- Closed
- related to
-
SERVER-38432 A session can expire on the server even when the driver is using it
- Closed