Skip to content

Commit

Permalink
Attempt to avoid deadlock during reconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilthoniel committed Aug 28, 2024
1 parent 953d9ea commit 0ac2862
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pulsar/consumer_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func newPartitionConsumer(parent Consumer, client *client, options *partitionCon
startMessageID: atomicMessageID{msgID: options.startMessageID},
connectedCh: make(chan struct{}),
messageCh: messageCh,
connectClosedCh: make(chan *connectionClosed, 10),
connectClosedCh: make(chan *connectionClosed, 1),
closeCh: make(chan struct{}),
clearQueueCh: make(chan func(id *trackingMessageID)),
compressionProviders: sync.Map{},
Expand Down Expand Up @@ -1381,9 +1381,14 @@ func (pc *partitionConsumer) ConnectionClosed(closeConsumer *pb.CommandCloseCons
assignedBrokerURL = pc.client.selectServiceURL(
closeConsumer.GetAssignedBrokerServiceUrl(), closeConsumer.GetAssignedBrokerServiceUrlTls())
}
pc.connectClosedCh <- &connectionClosed{
assignedBrokerURL: assignedBrokerURL,

select {
case pc.connectClosedCh <- &connectionClosed{assignedBrokerURL: assignedBrokerURL}:
default:
// Reconnect has already been requested so we do not block the
// connection callback.
}

}

func (pc *partitionConsumer) SetRedirectedClusterURI(redirectedClusterURI string) {
Expand Down
8 changes: 6 additions & 2 deletions pulsar/producer_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,12 @@ func (p *partitionProducer) ConnectionClosed(closeProducer *pb.CommandCloseProdu
assignedBrokerURL = p.client.selectServiceURL(
closeProducer.GetAssignedBrokerServiceUrl(), closeProducer.GetAssignedBrokerServiceUrlTls())
}
p.connectClosedCh <- &connectionClosed{
assignedBrokerURL: assignedBrokerURL,

select {
case p.connectClosedCh <- &connectionClosed{assignedBrokerURL: assignedBrokerURL}:
default:
// Reconnect has already been requested so we do not block the
// connection callback.
}
}

Expand Down

0 comments on commit 0ac2862

Please sign in to comment.