Skip to content

Commit 4add5f4

Browse files
authored
fix: check if context is nil before calling ctx.Deadline (#1630)
Signed-off-by: Krzysztof Jaskiewicz <[email protected]>
1 parent 6a53da6 commit 4add5f4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mongo/collection.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,11 @@ func (coll *Collection) Distinct(ctx context.Context, fieldName string, filter i
12001200
// For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/find/.
12011201
func (coll *Collection) Find(ctx context.Context, filter interface{},
12021202
opts ...*options.FindOptions) (cur *Cursor, err error) {
1203+
1204+
if ctx == nil {
1205+
ctx = context.Background()
1206+
}
1207+
12031208
// Omit "maxTimeMS" from operations that return a user-managed cursor to
12041209
// prevent confusing "cursor not found" errors. To maintain existing
12051210
// behavior for users who set "timeoutMS" with no context deadline, only
@@ -1217,10 +1222,6 @@ func (coll *Collection) find(
12171222
opts ...*options.FindOptions,
12181223
) (cur *Cursor, err error) {
12191224

1220-
if ctx == nil {
1221-
ctx = context.Background()
1222-
}
1223-
12241225
f, err := marshal(filter, coll.bsonOpts, coll.registry)
12251226
if err != nil {
12261227
return nil, err

0 commit comments

Comments
 (0)