[DOCS-11255] Document that 3.6 implicit sessions may cause noTimeout cursors to close while in use. Created: 24/Jan/18  Updated: 30/Oct/23  Resolved: 24/Feb/20

Status: Closed
Project: Documentation
Component/s: drivers, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Major - P3
Reporter: Shane Harvey Assignee: Ravind Kumar (Inactive)
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by DOCS-13011 noCursorTimeout can actually expire Closed
is duplicated by PYTHON-1879 no_cursor_timeout not functioning as ... Closed
Related
related to SERVER-38432 A session can expire on the server ev... Closed
is related to RUBY-3028 Document how to iterate cursor keepin... Backlog
is related to PYTHON-1880 Raise a warning when no_cursor_timeou... Closed
Participants:
Days since reply: 3 years, 50 weeks, 2 days ago
Epic Link: DOCSP-1769

 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


 Comments   
Comment by Githook User [ 24/Feb/20 ]

Author:

{'username': 'rkumar-mongo', 'name': 'Ravind Kumar', 'email': 'ravind.kumar@mongodb.com'}

Message: DOCS-11255: server session idle timeout overrides cursor timeout values
Branch: v3.6
https://github.com/mongodb/docs/commit/9a464998893588b2e0fa8d360dfe34d5b98b2430

Comment by Githook User [ 24/Feb/20 ]

Author:

{'username': 'rkumar-mongo', 'name': 'Ravind Kumar', 'email': 'ravind.kumar@mongodb.com'}

Message: DOCS-11255: server session idle timeout overrides cursor timeout values
Branch: v4.0
https://github.com/mongodb/docs/commit/581388d9e79b003e305ce357d8cc807fb63f5230

Comment by Githook User [ 24/Feb/20 ]

Author:

{'name': 'Ravind Kumar', 'username': 'rkumar-mongo', 'email': 'ravind.kumar@mongodb.com'}

Message: DOCS-11255: server session idle timeout overrides cursor timeout values
Branch: v4.2
https://github.com/mongodb/docs/commit/64c6a76d141fc74d001b2df2efa7383b627ab115

Comment by Githook User [ 24/Feb/20 ]

Author:

{'username': 'rkumar-mongo', 'name': 'Ravind Kumar', 'email': 'ravind.kumar@mongodb.com'}

Message: DOCS-11255: server session idle timeout overrides cursor timeout values
Branch: master
https://github.com/mongodb/docs/commit/3bf7ebfd3b85eb944c03dfeec8cf9f5a08f1ce4e

Comment by Ravind Kumar (Inactive) [ 06/Sep/19 ]

As a small update, i'm currently poking around this and am considering two stages to this fixup:

1) note (for all cursor-related docs) that the sessionTImeout overrides noCursorTimeout, and to use refreshSessions + explicit sessions for all ops to prevent session timeout.

2) for ops issued outside of a session, a combination of currentOp ( to retrieve the lsid) and refreshsessions should work instead.

1 I can finish must faster than 2, which will require some testing to confirm my thoughts.

Comment by Ravind Kumar (Inactive) [ 05/Sep/19 ]

alyson.cabral am I right in thinking that, for 3.6+, this means that any op that returns a cursor (find/agg in particular) can timeout after 30 minutes of session inactivity (no auth reresh) ?

e.g. a user starts an agg op that takes more than 30 minutes to return, session timeout kills the cursor?

If so then I think I'll have to call out this behavior in quite a few places. I'd also like to see if we can provide better guidance than 'run refreshSessions periodically for all open sessions'.

Comment by Nathan Leniz [ 05/Sep/19 ]

ravind.kumar I had looked into it but if you have time, please feel free.

Comment by Ravind Kumar (Inactive) [ 05/Sep/19 ]

nathan.leniz did you mean to assign this to yourself? If not I can take this to get it in the queue for this week.

Comment by Shane Harvey [ 05/Dec/18 ]

Note that because of SERVER-38432 it's not sufficient to run 'isMaster'. You need to run a command that requires auth such as refreshSessions.

Comment by Shane Harvey [ 25/Jan/18 ]

25 minutes also makes sense. The main point is that the user needs to manually refresh the session before it times out on the server.

Comment by Asya Kamsky [ 24/Jan/18 ]

Why 5 * 60? That's 5 minutes, right? Should be more like every 25 minutes, right?

Comment by Bernie Hackett [ 24/Jan/18 ]

This behavior change should be documented in the release notes for 3.6, and in the docs for the find command.

Generated at Thu Feb 08 08:02:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.