Skip to content

Commit

Permalink
fix case where context closes docs reader
Browse files Browse the repository at this point in the history
  • Loading branch information
FGasper committed Dec 7, 2024
1 parent 50708b7 commit 28b8525
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/verifier/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,17 @@ func iterateCursorToChannel(
cursor *mongo.Cursor,
writer chan<- bson.Raw,
) error {
defer close(writer)

for cursor.Next(ctx) {
state.NoteSuccess("received a document")
writer <- slices.Clone(cursor.Current)
}

close(writer)
select {
case <-ctx.Done():
return ctx.Err()
case writer <- slices.Clone(cursor.Current):
}
}

return errors.Wrap(cursor.Err(), "failed to iterate cursor")
}
Expand Down

0 comments on commit 28b8525

Please sign in to comment.