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

Use a separate gorutine to handle the logic of reconnect #691

Merged
merged 6 commits into from
Dec 27, 2021
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
16 changes: 12 additions & 4 deletions pulsar/producer_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ type partitionProducer struct {
batchFlushTicker *time.Ticker

// Channel where app is posting messages to be published
eventsChan chan interface{}
connectClosedCh chan connectionClosed
eventsChan chan interface{}

publishSemaphore internal.Semaphore
pendingQueue internal.BlockingQueue
Expand Down Expand Up @@ -115,8 +115,8 @@ func newPartitionProducer(client *client, topic string, options *ProducerOptions
log: logger,
options: options,
producerID: client.rpcClient.NewProducerID(),
eventsChan: make(chan interface{}, maxPendingMessages),
connectClosedCh: make(chan connectionClosed, 10),
eventsChan: make(chan interface{}, maxPendingMessages+20),
batchFlushTicker: time.NewTicker(batchingMaxPublishDelay),
publishSemaphore: internal.NewSemaphore(int32(maxPendingMessages)),
pendingQueue: internal.NewBlockingQueue(maxPendingMessages),
Expand Down Expand Up @@ -369,6 +369,16 @@ func (p *partitionProducer) reconnectToBroker() {
}

func (p *partitionProducer) runEventsLoop() {

go func() {
for {
for range p.connectClosedCh {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is going to leak a go routine since the p.connectClosedCh is never closed?

p.log.Info("runEventsLoop will reconnect in producer")
p.reconnectToBroker()
}
}
}()

for {
select {
case i := <-p.eventsChan:
Expand All @@ -381,8 +391,6 @@ func (p *partitionProducer) runEventsLoop() {
p.internalClose(v)
return
}
case <-p.connectClosedCh:
p.reconnectToBroker()
case <-p.batchFlushTicker.C:
if p.batchBuilder.IsMultiBatches() {
p.internalFlushCurrentBatches()
Expand Down