This is an automated email from the ASF dual-hosted git repository. jerrick pushed a commit to branch 2.6.x in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/2.6.x by this push: new 8ae95c9 Direct return when the server goes down unnormally. (#2451) 8ae95c9 is described below commit 8ae95c954228f1637d21b037df218a3ed94231c7 Author: 时无两丶 <442367...@qq.com> AuthorDate: Thu Sep 6 09:26:12 2018 +0800 Direct return when the server goes down unnormally. (#2451) --- .../alibaba/dubbo/remoting/exchange/Response.java | 5 +++++ .../remoting/exchange/support/DefaultFuture.java | 23 ++++++++++++++++++++++ .../support/header/HeaderExchangeHandler.java | 1 + 3 files changed, 29 insertions(+) diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/Response.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/Response.java index 0422a06..d01d20d 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/Response.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/Response.java @@ -41,6 +41,11 @@ public class Response { public static final byte SERVER_TIMEOUT = 31; /** + * channel inactive, directly return the unfinished requests. + */ + public static final byte CHANNEL_INACTIVE = 35; + + /** * request format error. */ public static final byte BAD_REQUEST = 40; diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/DefaultFuture.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/DefaultFuture.java index eccc86d..a72fadc 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/DefaultFuture.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/DefaultFuture.java @@ -90,6 +90,29 @@ public class DefaultFuture implements ResponseFuture { } } + /** + * close a channel when a channel is inactive + * directly return the unfinished requests. + * + * @param channel channel to close + */ + public static void closeChannel(Channel channel) { + for (long id : CHANNELS.keySet()) { + if (channel.equals(CHANNELS.get(id))) { + DefaultFuture future = getFuture(id); + if (future != null && !future.isDone()) { + Response disconnectResponse = new Response(future.getId()); + disconnectResponse.setStatus(Response.CHANNEL_INACTIVE); + disconnectResponse.setErrorMessage("Channel " + + channel + + " is inactive. Directly return the unFinished request : " + + future.getRequest()); + DefaultFuture.received(channel, disconnectResponse); + } + } + } + } + public static void received(Channel channel, Response response) { try { DefaultFuture future = FUTURES.remove(response.getId()); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/header/HeaderExchangeHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/header/HeaderExchangeHandler.java index 3c37817..f44318f 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/header/HeaderExchangeHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/header/HeaderExchangeHandler.java @@ -123,6 +123,7 @@ public class HeaderExchangeHandler implements ChannelHandlerDelegate { try { handler.disconnected(exchangeChannel); } finally { + DefaultFuture.closeChannel(channel); HeaderExchangeChannel.removeChannelIfDisconnected(channel); } }