From f7da387c7b798ced80fe855e52a2986670452ef5 Mon Sep 17 00:00:00 2001 From: Evan Huus Date: Mon, 27 Jul 2015 17:22:42 -0400 Subject: [PATCH] Fix a data race --- consumer.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/consumer.go b/consumer.go index c706b57719..43ce3b21bc 100644 --- a/consumer.go +++ b/consumer.go @@ -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: @@ -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 } } }