Browse Source

Fix potential NPEin Netty4Transport.stopInternal (#56080)

Closes #56069
Armin Braun 5 years ago
parent
commit
b3f48350d6

+ 7 - 8
modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java

@@ -307,15 +307,14 @@ public class Netty4Transport extends TcpTransport {
     @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<Channel> {