alts: fix server hang

Followup to #5893 which causes a server side hang. This is a hack.
This commit is contained in:
Carl Mastrangelo 2019-06-19 09:24:28 -07:00 committed by GitHub
parent e57d4c5a8e
commit 6e2bb6b402
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -34,9 +34,12 @@ import io.grpc.internal.ObjectPool;
import io.grpc.netty.GrpcHttp2ConnectionHandler;
import io.grpc.netty.InternalNettyChannelBuilder;
import io.grpc.netty.InternalNettyChannelBuilder.ProtocolNegotiatorFactory;
import io.grpc.netty.InternalProtocolNegotiationEvent;
import io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator;
import io.grpc.netty.InternalProtocolNegotiators;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.ssl.SslContext;
import io.netty.util.AsciiString;
import java.security.GeneralSecurityException;
@ -163,7 +166,26 @@ public final class AltsProtocolNegotiator {
ChannelHandler thh =
new TsiHandshakeHandler(gnh, nettyHandshaker, new AltsHandshakeValidator());
ChannelHandler wuah = InternalProtocolNegotiators.waitUntilActiveHandler(thh);
return wuah;
ChannelHandler knh = new KickNegotiationHandler(wuah);
return knh;
}
/** Kicks off negotiation of the server. This is a hack workaround until server uses WBAEH.*/
// TODO(carl-mastrangelo): remove this once NettyServerTransport uses WBAEH.
private static final class KickNegotiationHandler extends ChannelInboundHandlerAdapter {
private final ChannelHandler next;
KickNegotiationHandler(ChannelHandler next) {
this.next = checkNotNull(next, "next");
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
super.handlerAdded(ctx);
ctx.pipeline().replace(ctx.name(), /*newName= */ null, next);
ctx.pipeline().fireUserEventTriggered(InternalProtocolNegotiationEvent.getDefault());
}
}
@Override

View File

@ -36,7 +36,6 @@ import io.grpc.internal.FixedObjectPool;
import io.grpc.internal.GrpcAttributes;
import io.grpc.internal.ObjectPool;
import io.grpc.netty.GrpcHttp2ConnectionHandler;
import io.grpc.netty.InternalProtocolNegotiationEvent;
import io.grpc.netty.NettyChannelBuilder;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
@ -150,7 +149,6 @@ public class AltsProtocolNegotiatorTest {
new AltsProtocolNegotiator.ServerAltsProtocolNegotiator(handshakerFactory, lazyFakeChannel)
.newHandler(grpcHandler);
channel = new EmbeddedChannel(uncaughtExceptionHandler, handler);
channel.pipeline().fireUserEventTriggered(InternalProtocolNegotiationEvent.getDefault());
}
@After