lhotari commented on code in PR #24934:
URL: https://github.com/apache/pulsar/pull/24934#discussion_r2486427089
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractDispatcherSingleActiveConsumer.java:
##########
@@ -171,12 +187,26 @@ public synchronized CompletableFuture<Void>
addConsumer(Consumer consumer) {
if (subscriptionType == SubType.Exclusive && !consumers.isEmpty()) {
Consumer actConsumer = getActiveConsumer();
if (actConsumer != null) {
+ final var callerThread = Thread.currentThread();
return
actConsumer.cnx().checkConnectionLiveness().thenCompose(actConsumerStillAlive
-> {
if (actConsumerStillAlive.isEmpty() ||
actConsumerStillAlive.get()) {
return FutureUtil.failedFuture(new
ConsumerBusyException("Exclusive consumer is already"
+ " connected"));
} else {
- return addConsumer(consumer);
+ if (Thread.currentThread().equals(callerThread)) {
+ // A race condition happened in
`ServerCnx#channelInactive`
+ // 1. `isActive` was set to false
+ // 2. `consumer.close()` is called
+ // We should wait for the
+ log.warn("[{}] race condition happened that cnx of
the active consumer ({}) is inactive "
+ + "but it's not removed, retrying",
getName(), actConsumer);
+ final var future = new CompletableFuture<Void>();
+ CompletableFuture.delayedExecutor(100,
TimeUnit.MILLISECONDS)
+ .execute(() -> future.complete(null));
+ return future.thenCompose(__ ->
addConsumer(consumer));
+ } else {
+ return addConsumer(consumer);
Review Comment:
```suggestion
return internalAddConsumer(consumer, retryCount
+ 1);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]