From b2d9f9e142d6c8be12ad656d94facffe5917c77f Mon Sep 17 00:00:00 2001 From: Benoit Tellier Date: Mon, 21 Mar 2022 10:33:12 +0700 Subject: [PATCH] JAMES-3715 Close opened channels See https://github.com/apache/james-project/pull/898 for graceful shutdown --- .../james/protocols/netty/AbstractAsyncServer.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java index eefeff68f56..1e6bdb2ed73 100644 --- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java +++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java @@ -136,19 +136,20 @@ public synchronized void unbind() { workerGroup.shutdownGracefully(); } + if (channels != null) { + channels.close(); + } + started = false; } @Override public synchronized List getListenAddresses() { - ImmutableList.Builder builder = ImmutableList.builder(); - for (Channel channel : ImmutableList.copyOf(channels.iterator())) { - builder.add((InetSocketAddress) channel.localAddress()); - } - return builder.build(); + return channels.stream() + .map(channel -> (InetSocketAddress) channel.localAddress()) + .collect(ImmutableList.toImmutableList()); } - /** * Create ChannelPipelineFactory to use by this Server implementation */