@@ -203,10 +203,9 @@ instances at the same time (see the Server Session Pool section). Additionally,
203
203
a ``ClientSession `` may only ever be associated with one ``ServerSession `` for
204
204
its lifetime.
205
205
206
- Drivers MUST report an error if sessions are not supported by the deployment
207
- (see How to Check Whether a Deployment Supports Sessions). This error MUST either
208
- be reported by ``startSession ``, or be reported the first time the session is used
209
- for an operation.
206
+ Drivers MUST NOT check for session support in `startSession `. Instead, if sessions
207
+ are not supported, the error MUST be reported the first time the session is used
208
+ for an operation (See `How to Tell Whether a Connection Supports Sessions `_).
210
209
211
210
Explicit vs implicit sessions
212
211
-----------------------------
@@ -433,14 +432,14 @@ Existing database methods that start an implicit session
433
432
--------------------------------------------------------
434
433
435
434
When an existing ``MongoDatabase `` method that does not take a session is called,
436
- the driver MUST check whether the deployment supports sessions (See How to
437
- Check Whether a Deployment Supports Session). If sessions are supported, the
438
- driver MUST behave as if a new ``ClientSession `` was started just for this one
435
+ the driver MUST behave as if a new ``ClientSession `` was started just for this one
439
436
operation and ended immediately after this operation completes. The actual
440
437
implementation will likely involve calling ``client.startSession ``, but that is not
441
438
required by this spec. Regardless, please consult the startSession section to
442
439
replicate the required steps for creating a session.
443
- Drivers MUST NOT consume a server session id until after the connection is checked out.
440
+ The driver MUST NOT use the session if the checked out connection does not support sessions
441
+ (see `How to Tell Whether a Connection Supports Sessions `_) and, in all cases, MUST NOT consume a server
442
+ session id until after the connection is checked out and session support is confirmed.
444
443
445
444
MongoCollection changes
446
445
=======================
@@ -475,13 +474,14 @@ Existing collection methods that start an implicit session
475
474
----------------------------------------------------------
476
475
477
476
When an existing ``MongoCollection `` method that does not take a session is called,
478
- the driver MUST check whether the deployment supports sessions (See How to
479
- Check Whether a Deployment Supports Session). If sessions are supported, the
480
- driver MUST behave as if a new ``ClientSession `` was started just for this one
477
+ the driver MUST behave as if a new ``ClientSession `` was started just for this one
481
478
operation and ended immediately after this operation completes. The actual
482
479
implementation will likely involve calling ``client.startSession ``, but that is not
483
- required by this spec.
484
- Drivers MUST create an implicit session only after successfully checking out a connection.
480
+ required by this spec. Regardless, please consult the startSession section to
481
+ replicate the required steps for creating a session.
482
+ The driver MUST NOT use the session if the checked out connection does not support sessions
483
+ (see `How to Tell Whether a Connection Supports Sessions `_) and, in all cases, MUST NOT consume a server
484
+ session id until after the connection is checked out and session support is confirmed.
485
485
486
486
Sessions and Cursors
487
487
====================
@@ -502,68 +502,32 @@ A driver SHOULD NOT attempt to release the acquired session before connection ch
502
502
503
503
Explicit sessions MAY be changed to allocate a server session similarly.
504
504
505
- How to Check Whether a Deployment Supports Sessions
505
+ How to Tell Whether a Connection Supports Sessions
506
506
===================================================
507
507
508
- A driver can determine whether a deployment supports sessions by checking whether
509
- the ``logicalSessionTimeoutMinutes `` property of the ``TopologyDescription `` has
510
- a value or not. If it has a value the deployment supports sessions. However, in
511
- order for this determination to be valid, the driver MUST be connected to at least
512
- one server of a type that is `data-bearing
513
- <https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#data-bearing-server-type> `_.
514
- Therefore, the detailed steps to determine whether sessions are supported are:
515
-
516
- 1. If the ``TopologyDescription `` and connection type indicate that
517
-
518
- * the driver is not connected to any servers, OR
519
- * is not a direct connection AND is not connected to a data-bearing server
520
-
521
- then a driver must do a server selection for any server whose type is data-bearing.
522
- Server selection will either time out or result in a ``TopologyDescription `` that
523
- includes at least one connected, data-bearing server.
508
+ A driver can determine whether a connection supports sessions by checking whether
509
+ the ``logicalSessionTimeoutMinutes `` property of the establishing handshake response has
510
+ a value or not. If it has a value, sessions are supported.
524
511
525
- 2. Having verified in step 1 that the ``TopologyDescription `` includes at least
526
- one connected server a driver can now determine whether sessions are supported
527
- by inspecting the ``TopologyType `` and ``logicalSessionTimeoutMinutes `` property.
528
- When the ``TopologyType `` is ``LoadBalanced ``, sessions are always supported.
512
+ In the case of an explicit session, if sessions are not supported, the driver MUST raise an error.
513
+ In the case of an implicit session, if sessions are not supported, the driver MUST ignore the session.
529
514
530
- Possible race conditions when checking whether a deployment supports sessions
531
- -----------------------------------------------------------------------------
515
+ Possible race condition when checking for session support
516
+ ---------------------------------------------------------
532
517
533
- There are some possible race conditions that can happen between the time the
518
+ There is a possible race condition that can happen between the time the
534
519
driver checks whether sessions are supported and subsequently sends a command
535
520
to the server:
536
521
537
- * The TopologyDescription might be stale and no longer be accurate because it
538
- has been a few seconds since the last heartbeat.
539
-
540
- * The TopologyDescription might be accurate at the time the driver checks
541
- whether sessions are supported, but by the time the driver sends a command to
542
- the server it might no longer be accurate.
543
-
544
- * The TopologyDescription might be based on connections to a subset of the
545
- servers and it is possible that as the driver connects to more servers the
546
- driver might discover that sessions aren't supported after all.
547
-
548
522
* The server might have supported sessions at the time the connection was first
549
523
opened (and reported a value for logicalSessionTimeoutMinutes in the initial
550
524
response to the `handshake <https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst >`_),
551
525
but have subsequently been downgraded to not support sessions. The server does
552
- not close the socket in this scenario, and the driver will forever conclude that
553
- the server at the other end of this connection supports sessions. This scenario
554
- will only be a problem until the next heartbeat against that server.
555
-
556
- These race conditions are particularly insidious when the driver decides to
557
- start an implicit session based on the conclusion that sessions are supported.
558
- We don't want existing applications that don't use explicit sessions to fail
559
- when using implicit sessions.
560
-
561
- To handle these race conditions, the driver MUST ignore any implicit session if
562
- at the point it is sending a command to a specific server it turns out that
563
- that particular server doesn't support sessions after all. This handles the
564
- first three race conditions. There is nothing that the driver can do about the
565
- final race condition, and the server will just return an error in this
566
- scenario.
526
+ not close the socket in this scenario, so the driver will conclude that
527
+ the server at the other end of this connection supports sessions.
528
+
529
+ There is nothing that the driver can do about this race condition, and the server
530
+ will just return an error in this scenario.
567
531
568
532
Sending the session ID to the server on all commands
569
533
====================================================
@@ -1187,3 +1151,4 @@ Changelog
1187
1151
:2022-03-24: ServerSession Pooling is required and clarifies session acquisition bounding
1188
1152
:2022-06-13: Move prose tests to test README and apply new ordering
1189
1153
:2022-10-05: Remove spec front matter
1154
+ :2023-02-24: Defer checking for session support until after connection checkout
0 commit comments