Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s2a: Add S2AStub cleanup handler. #11600

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.common.util.concurrent.MoreExecutors;
import com.google.errorprone.annotations.ThreadSafe;
import io.grpc.Channel;
import io.grpc.ChannelLogger;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.ObjectPool;
import io.grpc.internal.SharedResourcePool;
Expand Down Expand Up @@ -179,6 +180,26 @@ public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
}
}

private static final class S2AStubCleanupNegotiationHandler extends ProtocolNegotiationHandler {
private final S2AStub s2aStub;

private S2AStubCleanupNegotiationHandler(
ChannelHandler next,
ChannelLogger logger,
S2AStub s2aStub) {
super(next, logger);
this.s2aStub = s2aStub;
}

@Override
protected void protocolNegotiationEventTriggered(ChannelHandlerContext ctx) {
s2aStub.close();
fireProtocolNegotiationEvent(ctx);
ctx.pipeline().remove(this);
ejona86 marked this conversation as resolved.
Show resolved Hide resolved
}

}

private static final class S2AProtocolNegotiationHandler extends ProtocolNegotiationHandler {
private final Channel channel;
private final Optional<S2AIdentity> localIdentity;
Expand Down Expand Up @@ -233,6 +254,9 @@ public void onSuccess(SslContext sslContext) {
SharedResourcePool.forResource(GrpcUtil.SHARED_CHANNEL_EXECUTOR))
.newHandler(grpcHandler);

ctx.pipeline().addAfter(ctx.name(), /* name= */ null,
larry-safran marked this conversation as resolved.
Show resolved Hide resolved
new S2AStubCleanupNegotiationHandler(handler,
ejona86 marked this conversation as resolved.
Show resolved Hide resolved
grpcHandler.getNegotiationLogger(), s2aStub));
// Remove the bufferReads handler and delegate the rest of the handshake to the TLS
larry-safran marked this conversation as resolved.
Show resolved Hide resolved
// handler.
ctx.pipeline().addAfter(ctx.name(), /* name= */ null, handler);
Expand Down