From 75d4a4def4ce86f160db2d6fd59266029e3a6756 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Mon, 4 May 2020 19:38:21 +0200 Subject: [PATCH] Fix potential NPEin Netty4Transport.stopInternal (#56080) (#56129) Closes #56068 --- .../transport/netty4/Netty4Transport.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java index 09d843ff6be44..3cdb5a92134b7 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java @@ -307,15 +307,14 @@ protected Netty4TcpServerChannel bind(String name, InetSocketAddress address) { @SuppressForbidden(reason = "debug") protected void stopInternal() { Releasables.close(() -> { - Future shutdownFuture = eventLoopGroup.shutdownGracefully(0, 5, TimeUnit.SECONDS); - shutdownFuture.awaitUninterruptibly(); - if (shutdownFuture.isSuccess() == false) { - logger.warn("Error closing netty event loop group", shutdownFuture.cause()); + if (eventLoopGroup != null) { + Future shutdownFuture = eventLoopGroup.shutdownGracefully(0, 5, TimeUnit.SECONDS); + shutdownFuture.awaitUninterruptibly(); + if (shutdownFuture.isSuccess() == false) { + logger.warn("Error closing netty event loop group", shutdownFuture.cause()); + } } - - serverBootstraps.clear(); - clientBootstrap = null; - }); + }, serverBootstraps::clear, () -> clientBootstrap = null); } protected class ClientChannelInitializer extends ChannelInitializer {