Skip to content

Commit 11f914c

Browse files
committed
1 parent 326b11b commit 11f914c

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/netty4/PortUnificationServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ protected void initChannel(SocketChannel ch) throws Exception {
136136
final ChannelPipeline p = ch.pipeline();
137137
PortUnificationServerHandler negotiation = new PortUnificationServerHandler(protocols);
138138
p.addLast("server-idle-handler", new IdleStateHandler(0, 0, idleTimeout, MILLISECONDS));
139-
p.addLast("negotiation",
140-
new PortUnificationServerHandler(protocols));
139+
p.addLast("negotiation", negotiation);
141140
channelGroup = negotiation.getChannels();
142141
}
143142
}
@@ -164,6 +163,7 @@ protected void doClose() throws Throwable {
164163
}
165164

166165
channelGroup.close();
166+
Thread.sleep(1000000);
167167
} catch (Throwable e) {
168168
logger.warn(e.getMessage(), e);
169169
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.apache.dubbo.rpc.protocol.tri;
2+
3+
import io.netty.channel.ChannelDuplexHandler;
4+
import io.netty.channel.ChannelHandler.Sharable;
5+
import io.netty.channel.ChannelHandlerContext;
6+
import io.netty.channel.ChannelInboundHandlerAdapter;
7+
import io.netty.channel.ChannelPipeline;
8+
import io.netty.channel.ChannelPromise;
9+
import io.netty.handler.codec.http2.Http2ConnectionDecoder;
10+
import io.netty.handler.codec.http2.Http2ConnectionEncoder;
11+
import io.netty.handler.codec.http2.Http2FrameCodec;
12+
import io.netty.handler.codec.http2.Http2FrameCodecBuilder;
13+
import io.netty.handler.codec.http2.Http2MultiplexHandler;
14+
import io.netty.handler.codec.http2.Http2Settings;
15+
import io.netty.handler.ssl.SslContext;
16+
import org.apache.dubbo.common.extension.Activate;
17+
import org.apache.dubbo.remoting.netty4.Http2WireProtocol;
18+
19+
20+
public class GracefulShutdownHandler extends Http2FrameCodec {
21+
22+
public GracefulShutdownHandler() {
23+
}
24+
25+
@Override
26+
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
27+
super.close(ctx, promise);
28+
new GracefulShutdown(ctx,"app_requested", null).gracefulShutdown();
29+
}
30+
}

dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/GrpcStatus.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public TripleRpcException asException(){
3737
enum Code {
3838
OK(0),
3939
UNKNOWN(2),
40+
DEADLINE_EXCEEDED(4),
4041
NOT_FOUND(5),
4142
RESOURCE_EXHAUSTED(8),
4243
UNIMPLEMENTED(12),

dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ServerStream.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.apache.dubbo.common.logger.Logger;
1717
import org.apache.dubbo.common.logger.LoggerFactory;
1818
import org.apache.dubbo.common.serialize.Serialization2;
19+
import org.apache.dubbo.remoting.TimeoutException;
1920
import org.apache.dubbo.rpc.AppResponse;
2021
import org.apache.dubbo.rpc.Invocation;
2122
import org.apache.dubbo.rpc.Invoker;
@@ -32,6 +33,7 @@
3233
import io.netty.handler.codec.http2.DefaultHttp2Headers;
3334
import io.netty.handler.codec.http2.DefaultHttp2HeadersFrame;
3435
import io.netty.handler.codec.http2.Http2Headers;
36+
import org.apache.dubbo.rpc.protocol.tri.GrpcStatus.Code;
3537

3638
import java.io.IOException;
3739
import java.util.concurrent.CompletionStage;
@@ -83,6 +85,9 @@ public void halfClose() {
8385
future.whenComplete((appResult, t) -> {
8486
try {
8587
if (t != null) {
88+
if (t instanceof TimeoutException) {
89+
responseErr(ctx, GrpcStatus.fromCode(Code.DEADLINE_EXCEEDED).withCause(t));
90+
}
8691
responseErr(ctx, GrpcStatus.fromCode(GrpcStatus.Code.UNKNOWN).withCause(t));
8792
return;
8893
}

dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHttp2Protocol.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public void configServerPipeline(ChannelPipeline pipeline) {
2828
.frameLogger(SERVER_LOGGER)
2929
.build();
3030
final Http2MultiplexHandler handler = new Http2MultiplexHandler(new TripleServerInitializer());
31+
pipeline.addLast("gracefulShutdown", new GracefulShutdownHandler());
3132
pipeline.addLast(codec, handler);
3233
}
3334

0 commit comments

Comments
 (0)