Skip to content

Commit

Permalink
[Fix][producer] Ensure all data in dataChan will be processed when in…
Browse files Browse the repository at this point in the history
…ternalClose() was called
  • Loading branch information
graysonzeng committed Jul 18, 2023
1 parent 3812c07 commit dbf81be
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pulsar/producer_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,11 +1266,27 @@ func (p *partitionProducer) ReceivedSendReceipt(response *pb.CommandSendReceipt)

func (p *partitionProducer) internalClose(req *closeProducer) {
defer close(req.doneCh)
defer close(p.dataChan)
defer close(p.cmdChan)
if !p.casProducerState(producerReady, producerClosing) {
return
}

p.log.Info("Closing producer")
for {
if len(p.dataChan) == 0 {
break
}
data := <-p.dataChan
p.internalSend(data)
}
flushReq := &flushRequest{
doneCh: make(chan struct{}),
err: nil,
}
p.internalFlush(flushReq)
// wait for the flush request to complete
<-flushReq.doneCh

id := p.client.rpcClient.NewRequestID()
_, err := p.client.rpcClient.RequestOnCnx(p._getConn(), id, pb.BaseCommand_CLOSE_PRODUCER, &pb.CommandCloseProducer{
Expand Down

0 comments on commit dbf81be

Please sign in to comment.