diff --git a/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java b/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java index 52c9a71742..c45a6ac6b2 100644 --- a/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java +++ b/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java @@ -611,7 +611,7 @@ public final class ProtocolNegotiators { BufferUntilTlsNegotiatedHandler( ChannelHandler bootstrapHandler, GrpcHttp2ConnectionHandler grpcHandler) { - super(bootstrapHandler, grpcHandler); + super(bootstrapHandler); this.grpcHandler = grpcHandler; } @@ -630,6 +630,10 @@ public final class ProtocolNegotiators { // Successfully negotiated the protocol. logSslEngineDetails(Level.FINER, ctx, "TLS negotiation succeeded.", null); + // Wait until negotiation is complete to add gRPC. If added too early, HTTP/2 writes + // will fail before we see the userEvent, and the channel is closed down prematurely. + ctx.pipeline().addBefore(ctx.name(), null, grpcHandler); + // Successfully negotiated the protocol. // Notify about completion and pass down SSLSession in attributes. grpcHandler.handleProtocolNegotiationCompleted(