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

[producer] Fix producer goroutine leak #331

Merged
merged 1 commit into from
Jul 24, 2020
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
18 changes: 14 additions & 4 deletions pulsar/producer_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type producer struct {
numPartitions uint32
messageRouter func(*ProducerMessage, TopicMetadata) int
ticker *time.Ticker
tickerStop chan struct{}

log *log.Entry
}
Expand Down Expand Up @@ -118,12 +119,19 @@ func newProducer(client *client, options *ProducerOptions) (*producer, error) {
return nil, err
}

p.ticker = time.NewTicker(partitionsAutoDiscoveryInterval)
ticker := time.NewTicker(partitionsAutoDiscoveryInterval)
p.ticker = ticker
p.tickerStop = make(chan struct{})

go func() {
for range p.ticker.C {
p.log.Debug("Auto discovering new partitions")
p.internalCreatePartitionsProducers()
for {
select {
case <-ticker.C:
p.log.Debug("Auto discovering new partitions")
p.internalCreatePartitionsProducers()
case <-p.tickerStop:
return
}
}
}()

Expand Down Expand Up @@ -282,6 +290,8 @@ func (p *producer) Close() {
defer p.RUnlock()
if p.ticker != nil {
p.ticker.Stop()
close(p.tickerStop)
p.ticker = nil
}

for _, pp := range p.producers {
Expand Down