Skip to content

Commit fb11692

Browse files
merlimatnikhil-ctds
authored andcommitted
[fix] Avoid NPE when closing an uninitialized SameAuthParamsLookupAutoClusterFailover (apache#23911)
(cherry picked from commit 12b0579) (cherry picked from commit c0ee989)
1 parent bc5a020 commit fb11692

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java

+3
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ private PulsarClientImpl(ClientConfigurationData conf, EventLoopGroup eventLoopG
253253
this::reduceConsumerReceiverQueueSize);
254254
state.set(State.Open);
255255
} catch (Throwable t) {
256+
// Log the exception first, or it could be missed if there are any subsequent exceptions in the
257+
// shutdown sequence
258+
log.error("Failed to create Pulsar client instance.", t);
256259
shutdown();
257260
shutdownEventLoopGroup(eventLoopGroupReference);
258261
closeCnxPool(connectionPoolReference);

pulsar-client/src/main/java/org/apache/pulsar/client/impl/SameAuthParamsLookupAutoClusterFailover.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,21 @@ public String getServiceUrl() {
107107

108108
@Override
109109
public void close() throws Exception {
110+
if (closed) {
111+
return;
112+
}
113+
110114
log.info("Closing service url provider. Current pulsar service: [{}] {}", currentPulsarServiceIndex,
111115
pulsarServiceUrlArray[currentPulsarServiceIndex]);
116+
if (scheduledCheckTask != null) {
117+
scheduledCheckTask.cancel(false);
118+
}
119+
120+
if (executor != null) {
121+
executor.shutdownNow();
122+
}
123+
112124
closed = true;
113-
scheduledCheckTask.cancel(false);
114-
executor.shutdownNow();
115125
}
116126

117127
private int firstHealthyPulsarService() {

0 commit comments

Comments
 (0)