Skip to content

Commit

Permalink
fixed NPE in pulsar client (apache#10470)
Browse files Browse the repository at this point in the history
* fixed NPE from pulsar client if we attempt to close the resource when conf.getServiceUrl is blank

* removed redundant check

* catching PulsarClientException instead of Throwable

* catching PulsarClientException instead of Throwable
  • Loading branch information
abhilashmandaliya authored May 3, 2021
1 parent 2cf9070 commit 27f5b62
Showing 1 changed file with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private PulsarClientImpl(ClientConfigurationData conf, EventLoopGroup eventLoopG
} catch (Throwable t) {
shutdown();
shutdownEventLoopGroup(eventLoopGroup);
closeCnxPool(cnxPool);
throw t;
}
}
Expand Down Expand Up @@ -714,17 +715,15 @@ public void shutdown() throws PulsarClientException {
// Shutting down eventLoopGroup separately because in some cases, cnxPool might be using different
// eventLoopGroup.
shutdownEventLoopGroup(eventLoopGroup);
} catch (Throwable t) {
log.warn("Failed to shutdown eventLoopGroup", t);
throwable = t;
} catch (PulsarClientException e) {
log.warn("Failed to shutdown eventLoopGroup", e);
throwable = e;
}
if (createdCnxPool) {
try {
cnxPool.close();
} catch (Throwable t) {
log.warn("Failed to shutdown cnxPool", t);
throwable = t;
}
try {
closeCnxPool(cnxPool);
} catch (PulsarClientException e) {
log.warn("Failed to shutdown cnxPool", e);
throwable = e;
}
if (timer != null && needStopTimer) {
try {
Expand All @@ -736,8 +735,8 @@ public void shutdown() throws PulsarClientException {
}
try {
shutdownExecutors();
} catch (Throwable t) {
throwable = t;
} catch (PulsarClientException e) {
throwable = e;
}
if (conf != null && conf.getAuthentication() != null) {
try {
Expand All @@ -764,8 +763,18 @@ public void shutdown() throws PulsarClientException {
}
}

private void closeCnxPool(ConnectionPool cnxPool) throws PulsarClientException {
if (createdCnxPool && cnxPool != null) {
try {
cnxPool.close();
} catch (Throwable t) {
throw PulsarClientException.unwrap(t);
}
}
}

private void shutdownEventLoopGroup(EventLoopGroup eventLoopGroup) throws PulsarClientException {
if (createdEventLoopGroup && !eventLoopGroup.isShutdown()) {
if (createdEventLoopGroup && eventLoopGroup != null && !eventLoopGroup.isShutdown()) {
try {
eventLoopGroup.shutdownGracefully().get();
} catch (Throwable t) {
Expand Down

0 comments on commit 27f5b62

Please sign in to comment.