Skip to content

Commit

Permalink
Merge pull request #734 from ChannelMeter/fix/timer-reset-logic
Browse files Browse the repository at this point in the history
Deadlock: Don't read from the timer channel if it already expired
  • Loading branch information
eapache committed Aug 23, 2016
2 parents 1639c3e + f0f5b0a commit 9489511
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,21 +414,24 @@ func (child *partitionConsumer) HighWaterMarkOffset() int64 {
func (child *partitionConsumer) responseFeeder() {
var msgs []*ConsumerMessage
expiryTimer := time.NewTimer(child.conf.Consumer.MaxProcessingTime)
expireTimedOut := false

feederLoop:
for response := range child.feeder {
msgs, child.responseResult = child.parseResponse(response)

for i, msg := range msgs {
if !expiryTimer.Stop() {
if !expiryTimer.Stop() && !expireTimedOut {
// expiryTimer was expired; clear out the waiting msg
<-expiryTimer.C
}
expiryTimer.Reset(child.conf.Consumer.MaxProcessingTime)
expireTimedOut = false

select {
case child.messages <- msg:
case <-expiryTimer.C:
expireTimedOut = true
child.responseResult = errTimedOut
child.broker.acks.Done()
for _, msg = range msgs[i:] {
Expand Down

0 comments on commit 9489511

Please sign in to comment.