From 9a7644140f0d2c5f3483a535f65ccc6dcf48e7cf Mon Sep 17 00:00:00 2001 From: "shengwei.psw" Date: Mon, 18 Jan 2021 20:43:10 +0800 Subject: [PATCH] #2 --- .../remoting/api/PortUnificationServer.java | 17 ++++++++++++----- .../rpc/protocol/tri/GracefulShutdown.java | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/api/PortUnificationServer.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/api/PortUnificationServer.java index 0635946e756..a125b10a2a2 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/api/PortUnificationServer.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/api/PortUnificationServer.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.remoting.api; +import io.netty.channel.group.ChannelGroupFuture; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.ImmediateEventExecutor; @@ -156,24 +157,30 @@ protected void doClose() throws Throwable { channel.close(); channel = null; } - long start = System.currentTimeMillis(); - channelGroup.close().addListener(new GenericFutureListener>() { + + ChannelGroupFuture closeFuture = channelGroup.close(); + closeFuture.addListener(new GenericFutureListener>() { @Override public void operationComplete(final Future future) throws Exception { + System.out.println("1shut operationComplete.."); if (!future.isSuccess()) { logger.warn("Error shutting down server", future.cause()); } System.out.println("shut operationComplete.."); - long now = System.currentTimeMillis(); + long start = System.currentTimeMillis(); + long now = start; while (now - start <= 15000 || channelGroup.size() > 0) { try { Thread.sleep(100); } catch (InterruptedException e) { } + now = System.currentTimeMillis(); } } - }).await(15000); - System.out.println("close cost:" + (System.currentTimeMillis()-start)); + }); + closeFuture.await(15000); + + System.out.println("close ..."); } catch (InterruptedException e) { System.out.println("Interrupted while shutting down" + e.getMessage()); logger.warn("Interrupted while shutting down", e); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/GracefulShutdown.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/GracefulShutdown.java index 4a8ac53605e..dba31343b59 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/GracefulShutdown.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/GracefulShutdown.java @@ -4,6 +4,7 @@ import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPromise; import io.netty.handler.codec.http2.DefaultHttp2GoAwayFrame; import io.netty.handler.codec.http2.DefaultHttp2PingFrame; import io.netty.handler.codec.http2.Http2Error; @@ -56,7 +57,7 @@ void secondGoAwayAndClose(ChannelHandlerContext ctx) { ctx.write(goAwayFrame); ctx.flush(); //gracefulShutdownTimeoutMillis - //ctx.close(); + ctx.close(); } catch (Exception e) { ctx.fireExceptionCaught(e); }