diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/netty4/DubboHttp2ConnectionHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/netty4/DubboHttp2ConnectionHandler.java index e52e102d841..6d5734f7398 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/netty4/DubboHttp2ConnectionHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/netty4/DubboHttp2ConnectionHandler.java @@ -6,8 +6,6 @@ import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; -import io.netty.handler.codec.http.HttpServerUpgradeHandler; -import io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler; import io.netty.handler.codec.http2.Http2Connection; import io.netty.handler.codec.http2.Http2ConnectionDecoder; import io.netty.handler.codec.http2.Http2ConnectionEncoder; @@ -18,10 +16,13 @@ import static io.netty.util.CharsetUtil.UTF_8; public class DubboHttp2ConnectionHandler extends Http2ConnectionHandler { - private ChannelHandlerContext ctx; + + static final long GRACEFUL_SHUTDOWN_PING = 0x97ACEF001L; + private final Http2ConnectionEncoder encoder; protected DubboHttp2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings initialSettings) { super(decoder, encoder, initialSettings); + this.encoder = encoder; } @Override @@ -33,6 +34,7 @@ public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exce ByteBufUtil.writeAscii(ctx.alloc(), "app_requested"), ctx.newPromise()); + encoder.writePing(ctx, false /* isAck */, GRACEFUL_SHUTDOWN_PING, ctx.newPromise()); super.close(ctx, promise); } @@ -51,8 +53,6 @@ public ChannelFuture goAway(final ChannelHandlerContext ctx, final int lastStrea return promise; } - // Need to retain before we write the buffer because if we do it after the refCnt could already be 0 and - // result in an IllegalRefCountException. debugData.retain(); ChannelFuture future = encoder.frameWriter().writeGoAway(ctx, lastStreamId, errorCode, debugData, promise); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/GrpcHttp2FrameListener.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/GrpcHttp2FrameListener.java index 749f4a3b3b2..d1bd379a557 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/GrpcHttp2FrameListener.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/GrpcHttp2FrameListener.java @@ -41,8 +41,6 @@ import org.apache.dubbo.rpc.model.ServiceRepository; import static io.netty.handler.codec.http.HttpResponseStatus.OK; -import static io.netty.handler.codec.http2.Http2Error.NO_ERROR; -import static io.netty.util.CharsetUtil.UTF_8; public class GrpcHttp2FrameListener extends Http2FrameAdapter { private TripleProtocol TRIPLE_PROTOCOL = TripleProtocol.getTripleProtocol(); @@ -96,9 +94,9 @@ public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int ByteBuf byteBuf = Marshaller.marshaller.marshaller(ctx.alloc(), response.getValue()); StreamData streamData = new StreamData(false, streamId, byteBuf); ctx.channel().write(streamData); - //final Http2Headers trailers = new DefaultHttp2Headers() - // .setInt(GrpcElf.GRPC_STATUS, Status.Code.OK.value()); - //ctx.channel().write(new StreamHeader(streamId, trailers, true)); + final Http2Headers trailers = new DefaultHttp2Headers() + .setInt(GrpcElf.GRPC_STATUS, Status.Code.OK.value()); + ctx.channel().write(new StreamHeader(streamId, trailers, true)); } } else { } @@ -115,6 +113,7 @@ private Invocation buildInvocation(Http2Headers http2Headers, ByteBuf data) { RpcInvocation inv = new RpcInvocation(); final String path = http2Headers.path().toString(); String[] parts = path.split("/"); + // todo String serviceName = "io.grpc.examples.helloworld.IGreeter"; String methodName = "sayHello"; ServiceRepository repo = ApplicationModel.getServiceRepository(); @@ -187,10 +186,6 @@ public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers Http2Request request = new Http2Request(streamId, http2Stream, headers, streamKey, marshaller, ctx.alloc()); http2Stream.setProperty(streamKey, request); - - if (endStream) { - - } } }