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: race condition(may panic) when closing consumer group #2331

Merged
merged 1 commit into from Sep 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions consumer_group.go
Expand Up @@ -86,9 +86,10 @@ type consumerGroup struct {
memberID string
errors chan error

lock sync.Mutex
closed chan none
closeOnce sync.Once
lock sync.Mutex
errorsLock sync.RWMutex
closed chan none
closeOnce sync.Once

userData []byte
}
Expand Down Expand Up @@ -156,10 +157,13 @@ func (c *consumerGroup) Close() (err error) {
err = e
}

// drain errors
go func() {
c.errorsLock.Lock()
defer c.errorsLock.Unlock()
close(c.errors)
}()

// drain errors
for e := range c.errors {
err = e
}
Expand Down Expand Up @@ -557,6 +561,8 @@ func (c *consumerGroup) handleError(err error, topic string, partition int32) {
return
}

c.errorsLock.RLock()
defer c.errorsLock.RUnlock()
select {
case <-c.closed:
// consumer is closed
Expand Down