Skip to content

Commit 0b15e7f

Browse files
fixup! Use mongoutil.TimeoutWithinContext over validChangeStreamTimeouts for change streams
1 parent 71e1d07 commit 0b15e7f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

mongo/change_stream.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,15 @@ func (cs *ChangeStream) loopNext(ctx context.Context, nonBlocking bool) {
686686
// operation-level timeout via contexts to a constructor and then that timeout
687687
// later be applied while working with a resulting cursor. Instead, it is more
688688
// idiomatic to apply the timeout to the context passed to Next or TryNext.
689-
if cs.options != nil && !nonBlocking && !mongoutil.TimeoutWithinContext(ctx, cs.options.MaxAwaitTime) {
690-
cs.err = fmt.Errorf("MaxAwaitTime must be less than the operation timeout")
689+
if cs.options != nil && !nonBlocking {
690+
maxAwaitTime := cs.cursorOptions.MaxAwaitTime
691691

692-
return
692+
// If maxAwaitTime is not set, this check is unnecessary.
693+
if maxAwaitTime != nil && !mongoutil.TimeoutWithinContext(ctx, *maxAwaitTime) {
694+
cs.err = fmt.Errorf("MaxAwaitTime must be less than the operation timeout")
695+
696+
return
697+
}
693698
}
694699

695700
// Apply the client-level timeout if the operation-level timeout is not set.

0 commit comments

Comments
 (0)