Skip to content

Commit

Permalink
[pulsar-client] clean up MultiTopicsConsumerImpl reference on consume…
Browse files Browse the repository at this point in the history
…r creation failure (apache#11754)
  • Loading branch information
rdhabalia authored Aug 24, 2021
1 parent 4e60de6 commit f154de7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class MultiTopicsConsumerImpl<T> extends ConsumerBase<T> {
private final ReadWriteLock lock = new ReentrantReadWriteLock();

private final ConsumerStatsRecorder stats;
private final UnAckedMessageTracker unAckedMessageTracker;
private UnAckedMessageTracker unAckedMessageTracker;
private final ConsumerConfigurationData<T> internalConfig;

private volatile BatchMessageIdImpl startMessageId = null;
Expand Down Expand Up @@ -543,7 +543,9 @@ public CompletableFuture<Void> unsubscribeAsync() {
@Override
public CompletableFuture<Void> closeAsync() {
if (getState() == State.Closing || getState() == State.Closed) {
unAckedMessageTracker.close();
if (unAckedMessageTracker != null) {
unAckedMessageTracker.close();
}
return CompletableFuture.completedFuture(null);
}
setState(State.Closing);
Expand Down Expand Up @@ -580,7 +582,14 @@ public CompletableFuture<Void> closeAsync() {
}

private void cleanupMultiConsumer() {
unAckedMessageTracker.close();
if (unAckedMessageTracker != null) {
unAckedMessageTracker.close();
unAckedMessageTracker = null;
}
if (partitionsAutoUpdateTimeout != null) {
partitionsAutoUpdateTimeout.cancel();
partitionsAutoUpdateTimeout = null;
}
client.cleanupConsumer(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ private void stop() {
try {
if (timeout != null && !timeout.isCancelled()) {
timeout.cancel();
timeout = null;
}
this.clear();
} finally {
Expand Down

0 comments on commit f154de7

Please sign in to comment.