Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hypothetical consumer deadlock, attempt 2 #484

Merged
merged 1 commit into from
Jul 27, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (c *consumer) ConsumePartition(topic string, partition int32, offset int64)
errors: make(chan *ConsumerError, c.conf.ChannelBufferSize),
feeder: make(chan *FetchResponse, 1),
trigger: make(chan none, 1),
dying: make(chan error, 1),
dying: make(chan none),
fetchSize: c.conf.Consumer.Fetch.Default,
}

Expand Down Expand Up @@ -269,8 +269,9 @@ type partitionConsumer struct {
messages chan *ConsumerMessage
errors chan *ConsumerError
feeder chan *FetchResponse
trigger chan none
dying chan error

trigger, dying chan none
dispatchReason error

fetchSize int32
offset int64
Expand Down Expand Up @@ -372,7 +373,7 @@ func (child *partitionConsumer) AsyncClose() {
// the dispatcher to exit its loop, which removes it from the consumer then closes its 'messages' and
// 'errors' channel (alternatively, if the child is already at the dispatcher for some reason, that will
// also just close itself)
child.dying <- nil
close(child.dying)
}

func (child *partitionConsumer) Close() error {
Expand Down Expand Up @@ -412,11 +413,11 @@ func (child *partitionConsumer) responseFeeder() {
child.AsyncClose()
case ErrUnknownTopicOrPartition, ErrNotLeaderForPartition, ErrLeaderNotAvailable:
// these three are not fatal errors, but do require redispatching
child.dying <- err
child.dispatchReason = err
default:
// dunno, tell the user and try redispatching
child.sendError(err)
child.dying <- err
child.dispatchReason = err
}

child.broker.acks.Done()
Expand Down Expand Up @@ -602,16 +603,18 @@ func (bc *brokerConsumer) updateSubscriptionCache(newSubscriptions []*partitionC

for child := range bc.subscriptions {
select {
case err := <-child.dying:
if err == nil {
Logger.Printf("consumer/broker/%d closed dead subscription to %s/%d\n", bc.broker.ID(), child.topic, child.partition)
close(child.trigger)
} else {
Logger.Printf("consumer/broker/%d abandoned subscription to %s/%d because %s\n", bc.broker.ID(), child.topic, child.partition, err)
child.trigger <- none{}
}
case <-child.dying:
Logger.Printf("consumer/broker/%d closed dead subscription to %s/%d\n", bc.broker.ID(), child.topic, child.partition)
close(child.trigger)
delete(bc.subscriptions, child)
default:
if child.dispatchReason != nil {
Logger.Printf("consumer/broker/%d abandoned subscription to %s/%d because %s\n",
bc.broker.ID(), child.topic, child.partition, child.dispatchReason)
child.dispatchReason = nil
child.trigger <- none{}
delete(bc.subscriptions, child)
}
}
}
}
Expand Down