Skip to content

Commit

Permalink
Fix a data race
Browse files Browse the repository at this point in the history
  • Loading branch information
eapache committed Jul 27, 2015
1 parent a53ff72 commit f7da387
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,10 @@ func (bc *brokerConsumer) handleResponses() {
close(child.trigger)
delete(bc.subscriptions, child)
default:
switch child.responseResult {
result := child.responseResult
child.responseResult = nil

switch result {
case nil:
break
case errTimedOut:
Expand All @@ -620,26 +623,24 @@ func (bc *brokerConsumer) handleResponses() {
case ErrOffsetOutOfRange:
// there's no point in retrying this it will just fail the same way again
// shut it down and force the user to choose what to do
child.sendError(child.responseResult)
Logger.Printf("consumer/%s/%d shutting down because %s\n", child.topic, child.partition, child.responseResult)
child.sendError(result)
Logger.Printf("consumer/%s/%d shutting down because %s\n", child.topic, child.partition, result)
close(child.trigger)
delete(bc.subscriptions, child)
case ErrUnknownTopicOrPartition, ErrNotLeaderForPartition, ErrLeaderNotAvailable:
// not an error, but does need redispatching
Logger.Printf("consumer/broker/%d abandoned subscription to %s/%d because %s\n",
bc.broker.ID(), child.topic, child.partition, child.responseResult)
bc.broker.ID(), child.topic, child.partition, result)
child.trigger <- none{}
delete(bc.subscriptions, child)
default:
// dunno, tell the user and try redispatching
child.sendError(child.responseResult)
child.sendError(result)
Logger.Printf("consumer/broker/%d abandoned subscription to %s/%d because %s\n",
bc.broker.ID(), child.topic, child.partition, child.responseResult)
bc.broker.ID(), child.topic, child.partition, result)
child.trigger <- none{}
delete(bc.subscriptions, child)
}

child.responseResult = nil
}
}
}
Expand Down

0 comments on commit f7da387

Please sign in to comment.