From 417765b8145866552369b24d44e346a19c203304 Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Thu, 25 Jan 2018 11:51:24 -0800 Subject: [PATCH] netty: only add gRPC negotiator once SSL is established --- netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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(