Skip to content

Commit

Permalink
pulsar/producer_impl: avoid consequtive Close calls side-effects by w…
Browse files Browse the repository at this point in the history
…rapping method body with sync.Once (similar to consumer.Close)
  • Loading branch information
PowerStateFailure committed Feb 28, 2021
1 parent 2032bfd commit aaea56d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pulsar/producer_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type producer struct {
producersPtr unsafe.Pointer
numPartitions uint32
messageRouter func(*ProducerMessage, TopicMetadata) int
closeOnce sync.Once
stopDiscovery func()
log log.Logger
metrics *internal.TopicMetrics
Expand Down Expand Up @@ -303,18 +304,17 @@ func (p *producer) Flush() error {
}

func (p *producer) Close() {
if p.stopDiscovery != nil {
p.closeOnce.Do(func() {
p.stopDiscovery()
p.stopDiscovery = nil
}

p.Lock()
defer p.Unlock()
p.Lock()
defer p.Unlock()

for _, pp := range p.producers {
pp.Close()
}
p.client.handlers.Del(p)
p.metrics.ProducersPartitions.Sub(float64(len(p.producers)))
p.metrics.ProducersClosed.Inc()
for _, pp := range p.producers {
pp.Close()
}
p.client.handlers.Del(p)
p.metrics.ProducersPartitions.Sub(float64(len(p.producers)))
p.metrics.ProducersClosed.Inc()
})
}

0 comments on commit aaea56d

Please sign in to comment.