Skip to content

Commit 28b8525

Browse files
committed
fix case where context closes docs reader
1 parent 50708b7 commit 28b8525

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

internal/verifier/compare.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,17 @@ func iterateCursorToChannel(
375375
cursor *mongo.Cursor,
376376
writer chan<- bson.Raw,
377377
) error {
378+
defer close(writer)
379+
378380
for cursor.Next(ctx) {
379381
state.NoteSuccess("received a document")
380-
writer <- slices.Clone(cursor.Current)
381-
}
382382

383-
close(writer)
383+
select {
384+
case <-ctx.Done():
385+
return ctx.Err()
386+
case writer <- slices.Clone(cursor.Current):
387+
}
388+
}
384389

385390
return errors.Wrap(cursor.Err(), "failed to iterate cursor")
386391
}

0 commit comments

Comments
 (0)