Skip to content

Commit 8ae95c9

Browse files
carryxyhjerrick-zhu
authored andcommitted
Direct return when the server goes down unnormally. (#2451)
1 parent c7e7c14 commit 8ae95c9

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/Response.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public class Response {
4040
*/
4141
public static final byte SERVER_TIMEOUT = 31;
4242

43+
/**
44+
* channel inactive, directly return the unfinished requests.
45+
*/
46+
public static final byte CHANNEL_INACTIVE = 35;
47+
4348
/**
4449
* request format error.
4550
*/

dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/DefaultFuture.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,29 @@ public static void sent(Channel channel, Request request) {
9090
}
9191
}
9292

93+
/**
94+
* close a channel when a channel is inactive
95+
* directly return the unfinished requests.
96+
*
97+
* @param channel channel to close
98+
*/
99+
public static void closeChannel(Channel channel) {
100+
for (long id : CHANNELS.keySet()) {
101+
if (channel.equals(CHANNELS.get(id))) {
102+
DefaultFuture future = getFuture(id);
103+
if (future != null && !future.isDone()) {
104+
Response disconnectResponse = new Response(future.getId());
105+
disconnectResponse.setStatus(Response.CHANNEL_INACTIVE);
106+
disconnectResponse.setErrorMessage("Channel " +
107+
channel +
108+
" is inactive. Directly return the unFinished request : " +
109+
future.getRequest());
110+
DefaultFuture.received(channel, disconnectResponse);
111+
}
112+
}
113+
}
114+
}
115+
93116
public static void received(Channel channel, Response response) {
94117
try {
95118
DefaultFuture future = FUTURES.remove(response.getId());

dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/header/HeaderExchangeHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public void disconnected(Channel channel) throws RemotingException {
123123
try {
124124
handler.disconnected(exchangeChannel);
125125
} finally {
126+
DefaultFuture.closeChannel(channel);
126127
HeaderExchangeChannel.removeChannelIfDisconnected(channel);
127128
}
128129
}

0 commit comments

Comments
 (0)