@@ -334,10 +334,10 @@ resulting cursor but MUST NOT append a `maxTimeMS` field to any commands.
334334##### Tailable awaitData Cursors
335335
336336If ` timeoutMS ` is set, drivers MUST apply it to the original operation. Drivers MUST also apply the original ` timeoutMS `
337- value to each ` next ` call on the resulting cursor but MUST NOT use it to derive a ` maxTimeMS ` value for ` getMore `
338- commands. Helpers for operations that create tailable awaitData cursors MUST also support the ` maxAwaitTimeMS ` option.
339- Drivers MUST error if this option is set, ` timeoutMS ` is set to a non-zero value, and ` maxAwaitTimeMS ` is greater than
340- or equal to ` timeoutMS ` . If this option is set, drivers MUST use it as the ` maxTimeMS ` field on ` getMore ` commands.
337+ value to each ` next ` call on the resulting cursor. Helpers for operations that create tailable awaitData cursors MUST
338+ also support the ` maxAwaitTimeMS ` option. Drivers MUST error if this option is set, ` timeoutMS ` is set to a non-zero
339+ value, and ` maxAwaitTimeMS ` is greater than or equal to ` timeoutMS ` . If this option is set, drivers MUST use
340+ ` min(maxAwaitTimeMS, remaining timeoutMS - minRoundTripTime) ` as the ` maxTimeMS ` field on ` getMore ` commands.
341341
342342See [ Tailable cursor behavior] ( #tailable-cursor-behavior ) for rationale regarding both non-awaitData and awaitData
343343cursors.
@@ -349,8 +349,8 @@ Driver `watch` helpers MUST support both `timeoutMS` and `maxAwaitTimeMS` option
349349` timeoutMS ` . These helpers MUST NOT support the ` timeoutMode ` option as change streams are an abstraction around
350350tailable-awaitData cursors, so they implicitly use ` ITERATION ` mode. If set, drivers MUST apply the ` timeoutMS ` option
351351to the initial ` aggregate ` operation. Drivers MUST also apply the original ` timeoutMS ` value to each ` next ` call on the
352- change stream but MUST NOT use it to derive a ` maxTimeMS ` field for ` getMore ` commands. If the ` maxAwaitTimeMS ` option
353- is set, drivers MUST use it as the ` maxTimeMS ` field on ` getMore ` commands.
352+ change stream. If this option is set, drivers MUST use ` min(maxAwaitTimeMS, remaining timeoutMS - minRoundTripTime) ` as
353+ the ` maxTimeMS ` field on ` getMore ` commands.
354354
355355If a ` next ` call fails with a timeout error, drivers MUST NOT invalidate the change stream. The subsequent ` next ` call
356356MUST perform a resume attempt to establish a new change stream on the server. Any errors from the ` aggregate ` operation
@@ -600,6 +600,9 @@ distinct meanings, so supporting both yields a more robust, albeit verbose, API.
600600greater than or equal to ` timeoutMS ` because in that case, ` getMore ` requests would not succeed if the batch was empty:
601601the server would wait for ` maxAwaitTimeMS ` , but the driver would close the socket after ` timeoutMS ` .
602602
603+ For tailable awaitData cursors we use the ` min(maxAwaitTimeMS, remaining timeoutMS - minRoundTripTime) ` to allow the
604+ server more opportunities to respond with an empty batch before a client-side timeout
605+
603606### Change stream behavior
604607
605608Change streams internally behave as tailable awaitData cursors, so the behavior of the ` timeoutMS ` option is the same
@@ -665,6 +668,7 @@ timeout for each database operation. This would mimic using `timeoutMode=ITERATI
665668
666669## Changelog
667670
671+ - 2024-01-29: Adjust getMore maxTimeMS calculation for tailable awaitData cursors.
668672- 2024-09-12: Specify that explain helpers support support timeoutMS.
669673- 2023-12-07: Migrated from reStructuredText to Markdown.
670674- 2022-11-17: Use minimum RTT for maxTimeMS calculation instead of 90th percentile RTT.
0 commit comments