Skip to content

Commit

Permalink
Prevent fast iterations over err + respect ctx cancellation (#24)
Browse files Browse the repository at this point in the history
* Prevent fast iterations over err + respect ctx cancellation
* Only sleep when err isn't redis.Nil
  • Loading branch information
cameron-dunn-sublime authored Apr 6, 2022
1 parent 7542814 commit b31b952
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/go/cmd/strelka-frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,16 @@ func (s *server) ScanFile(stream strelka.Frontend_ScanFileServer) error {
}

for {
if err := stream.Context().Err(); err != nil {
return err
}

res, err := s.coordinator.cli.BLPop(stream.Context(), 5*time.Second, keye).Result()
if err != nil {
if err != redis.Nil {
// Delay to prevent fast looping over errors
time.Sleep(250 * time.Millisecond)
}
continue
}
// first element will be the name of queue/event, second element is event itself
Expand Down

0 comments on commit b31b952

Please sign in to comment.