Skip to content

Commit

Permalink
Merge pull request #16 from go-playground/additional-protection
Browse files Browse the repository at this point in the history
protect inner context.Context mis-use
  • Loading branch information
deankarn authored Jul 26, 2022
2 parents b60a02d + 24f3cb9 commit a5fbcf5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,17 @@ func (c *Consumer[P, S, T]) Start(ctx context.Context) (err error) {
go func() {
defer wg.Done()
err := c.worker(ctx, ch)
if err != nil && !errors.Is(err, context.Canceled) {
if err != nil {
if errors.Is(err, context.Canceled) {
// double check it our context we passed in that got cancelled and not some inner
// one through mis-use. Protect people from themselves.
select {
case <-ctx.Done():
return
default:
log.Fatal(errors.Wrap(err, "issue encountered processing Jobs. It appears to be a misuse of the context.Context."))
}
}
log.Fatal(errors.Wrap(err, "issue encountered processing Jobs"))
}
}()
Expand Down

0 comments on commit a5fbcf5

Please sign in to comment.