Skip to content

Commit

Permalink
fix: check if context is nil before calling ctx.Deadline (#1630)
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Jaskiewicz <[email protected]>
  • Loading branch information
kjaskiewiczz authored May 8, 2024
1 parent 6a53da6 commit 4add5f4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mongo/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,11 @@ func (coll *Collection) Distinct(ctx context.Context, fieldName string, filter i
// For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/find/.
func (coll *Collection) Find(ctx context.Context, filter interface{},
opts ...*options.FindOptions) (cur *Cursor, err error) {

if ctx == nil {
ctx = context.Background()
}

// Omit "maxTimeMS" from operations that return a user-managed cursor to
// prevent confusing "cursor not found" errors. To maintain existing
// behavior for users who set "timeoutMS" with no context deadline, only
Expand All @@ -1217,10 +1222,6 @@ func (coll *Collection) find(
opts ...*options.FindOptions,
) (cur *Cursor, err error) {

if ctx == nil {
ctx = context.Background()
}

f, err := marshal(filter, coll.bsonOpts, coll.registry)
if err != nil {
return nil, err
Expand Down

0 comments on commit 4add5f4

Please sign in to comment.