-
Notifications
You must be signed in to change notification settings - Fork 916
GODRIVER-3473 Short-cicruit cursor.next() on invalid timeouts #2135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
API Change Report./v2/x/mongo/drivercompatible changes(*BatchCursor).MaxAwaitTime: added |
9bb1fb5
to
5006d50
Compare
// TimeoutWithinContext will return true if the provided timeout is nil or if | ||
// it is less than the context deadline. If the context does not have a | ||
// deadline, it will return true. | ||
func TimeoutWithinContext(ctx context.Context, timeout *time.Duration) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simplify the behavior by letting the caller decide what a nil
timeout means. TimeoutWIthinContext
should take a time.Duration
instead of a *time.Duration
.
mt.Run("short-circuiting getMore", func(mt *mtest.T) { | ||
tests := []struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This subtest should be refactored into one or many test functions.
|
||
var docs []interface{} | ||
for i := 1; i <= 5; i++ { | ||
docs = append(docs, bson.D{{"x", int32(i)}}) | ||
} | ||
|
||
_, err := coll.InsertMany(context.Background(), docs) | ||
assert.Nil(mt, err, "InsertMany error for initial data: %v", err) | ||
assert.Nil(tb, err, "InsertMany error for initial data: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Consider using assert.NoError
mt.RunOpts("apply remaining timeoutMS if less than maxAwaitTimeMS", mtOpts, func(mt *mtest.T) { | ||
cappedColl := newCappedCollection(mt, "tailable_awaitData_capped") | ||
initCollection(mt, cappedColl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: You can use mtest.Options.CollectionCreateOptions
to create a capped collection.
GODRIVER-3473
Summary
Short-circuit calls to
cursor.Next()
where maxAwaitTimeMS >= operation timeout, which would result in socket timeouts.Background & Motivation
The specifications assume that drivers iteratively apply the timeout provided at the constructor level (e.g.,
(*collection).Find
) for tailable awaitData cursors:The Go Driver might decide to support the above behavior with DRIVERS-2722. The principal concern is that it would be unexpected for users to apply an operation-level timeout via contexts to a constructor and then have that timeout later be applied while working with a resulting cursor. Instead, it is more idiomatic to apply the timeout to the context passed to
Next
orTryNext
.