diff --git a/hippo4j-rpc/src/main/java/cn/hippo4j/rpc/client/NettyClientConnection.java b/hippo4j-rpc/src/main/java/cn/hippo4j/rpc/client/NettyClientConnection.java index 0c9e8e66..fce2deba 100644 --- a/hippo4j-rpc/src/main/java/cn/hippo4j/rpc/client/NettyClientConnection.java +++ b/hippo4j-rpc/src/main/java/cn/hippo4j/rpc/client/NettyClientConnection.java @@ -108,7 +108,7 @@ public class NettyClientConnection implements ClientConnection { } @Override - public void close() { + public synchronized void close() { if (this.channel == null) { return; } diff --git a/hippo4j-rpc/src/main/java/cn/hippo4j/rpc/server/NettyServerConnection.java b/hippo4j-rpc/src/main/java/cn/hippo4j/rpc/server/NettyServerConnection.java index 62bf0551..49083c03 100644 --- a/hippo4j-rpc/src/main/java/cn/hippo4j/rpc/server/NettyServerConnection.java +++ b/hippo4j-rpc/src/main/java/cn/hippo4j/rpc/server/NettyServerConnection.java @@ -105,12 +105,13 @@ public class NettyServerConnection extends AbstractNettyHandlerManager implement } @Override - public void close() { + public synchronized void close() { if (port == null) { return; } - leader.shutdownGracefully(); - worker.shutdownGracefully(); + this.leader.shutdownGracefully(); + this.worker.shutdownGracefully(); + this.channel.close(); this.future.channel().close(); log.info("The server is shut down and no more requests are received. The release port is {}", port.getPort()); } @@ -146,4 +147,5 @@ public class NettyServerConnection extends AbstractNettyHandlerManager implement super.addFirst(handler); return this; } + } diff --git a/hippo4j-rpc/src/test/java/cn/hippo4j/rpc/support/NettyServerSupportTest.java b/hippo4j-rpc/src/test/java/cn/hippo4j/rpc/support/NettyServerSupportTest.java index 32dc81d8..cc193082 100644 --- a/hippo4j-rpc/src/test/java/cn/hippo4j/rpc/support/NettyServerSupportTest.java +++ b/hippo4j-rpc/src/test/java/cn/hippo4j/rpc/support/NettyServerSupportTest.java @@ -27,7 +27,7 @@ import java.io.IOException; public class NettyServerSupportTest { @Test - public void bind() throws IOException { + public synchronized void bind() throws IOException { NettyServerSupport support = new NettyServerSupport(() -> 8891, InstanceServerLoader.class); support.bind(); while (!support.isActive()) { @@ -35,6 +35,7 @@ public class NettyServerSupportTest { } Assert.assertTrue(support.isActive()); support.close(); + ThreadUtil.sleep(1000L); Assert.assertFalse(support.isActive()); }