Skip to content

Commit

Permalink
fix: ensure backoff timer is re-used
Browse files Browse the repository at this point in the history
Unlikely to cause an issue in Sarama unless the user explicitly set
Metadata.Retry.Backoff especially high and was hitting lots of retry
conditions, but no harm in guarding against this.

Ref: https://medium.com/@oboturov/golang-time-after-is-not-garbage-collected-4cbc94740082
  • Loading branch information
dnwe committed Jun 8, 2021
1 parent fca0631 commit 4932617
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions consumer_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@ func (s *consumerGroupSession) heartbeatLoop() {
pause := time.NewTicker(s.parent.config.Consumer.Group.Heartbeat.Interval)
defer pause.Stop()

retryBackoff := time.NewTimer(s.parent.config.Metadata.Retry.Backoff)
defer retryBackoff.Stop()

retries := s.parent.config.Metadata.Retry.Max
for {
coordinator, err := s.parent.client.Coordinator(s.parent.groupID)
Expand All @@ -740,11 +743,11 @@ func (s *consumerGroupSession) heartbeatLoop() {
s.parent.handleError(err, "", -1)
return
}

retryBackoff.Reset(s.parent.config.Metadata.Retry.Backoff)
select {
case <-s.hbDying:
return
case <-time.After(s.parent.config.Metadata.Retry.Backoff):
case <-retryBackoff.C:
retries--
}
continue
Expand Down

0 comments on commit 4932617

Please sign in to comment.