diecui1202 closed pull request #2451: Direct return when the server goes down
unnormally.
URL: https://github.com/apache/incubator-dubbo/pull/2451
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 0422a06367..d01d20d663 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
@@ -40,6 +40,11 @@
*/
public static final byte SERVER_TIMEOUT = 31;
+ /**
+ * channel inactive, directly return the unfinished requests.
+ */
+ public static final byte CHANNEL_INACTIVE = 35;
+
/**
* request format error.
*/
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 eccc86d481..a72fadc5d0 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 static void sent(Channel channel, Request request) {
}
}
+ /**
+ * 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 3c378178e1..f44318f7c4 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 void disconnected(Channel channel) throws
RemotingException {
try {
handler.disconnected(exchangeChannel);
} finally {
+ DefaultFuture.closeChannel(channel);
HeaderExchangeChannel.removeChannelIfDisconnected(channel);
}
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]