Skip to content

Commit

Permalink
Consumer: fix deadlock - if the timer had already expired, don't try …
Browse files Browse the repository at this point in the history
…to read the channel again.
  • Loading branch information
nemosupremo committed Aug 23, 2016
1 parent 779ef6a commit f0f5b0a
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 f0f5b0a

Please sign in to comment.