Skip to content
Merged
Show file tree
Hide file tree
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 @@ -180,6 +180,7 @@ static final class ClientSdsHandler
extends InternalProtocolNegotiators.ProtocolNegotiationHandler {
private final GrpcHttp2ConnectionHandler grpcHandler;
private final SslContextProviderSupplier sslContextProviderSupplier;
private volatile boolean handlerRemoved;

ClientSdsHandler(
GrpcHttp2ConnectionHandler grpcHandler,
Expand Down Expand Up @@ -209,6 +210,9 @@ protected void handlerAdded0(final ChannelHandlerContext ctx) {

@Override
public void updateSslContext(SslContext sslContext) {
if (handlerRemoved) {
return;
}
logger.log(
Level.FINEST,
"ClientSdsHandler.updateSslContext authority={0}, ctx.name={1}",
Expand All @@ -230,6 +234,12 @@ public void onException(Throwable throwable) {
);
}

@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
handlerRemoved = true;
super.handlerRemoved(ctx);
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,36 @@ protected void onException(Throwable throwable) {
CommonCertProviderTestUtils.register0();
}

@Test
public void clientSdsProtocolNegotiatorNewHandler_handleHandlerRemoved() {
FakeClock executor = new FakeClock();
CommonCertProviderTestUtils.register(executor);
Bootstrapper.BootstrapInfo bootstrapInfoForClient = CommonBootstrapperTestUtils
.buildBootstrapInfo("google_cloud_private_spiffe-client", CLIENT_KEY_FILE, CLIENT_PEM_FILE,
CA_PEM_FILE, null, null, null, null);
UpstreamTlsContext upstreamTlsContext =
CommonTlsContextTestsUtil
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true);

SslContextProviderSupplier sslContextProviderSupplier =
new SslContextProviderSupplier(upstreamTlsContext,
new TlsContextManagerImpl(bootstrapInfoForClient));
SecurityProtocolNegotiators.ClientSdsHandler clientSdsHandler =
new SecurityProtocolNegotiators.ClientSdsHandler(grpcHandler, sslContextProviderSupplier);

pipeline.addLast(clientSdsHandler);
channelHandlerCtx = pipeline.context(clientSdsHandler);

// kick off protocol negotiation.
pipeline.fireUserEventTriggered(InternalProtocolNegotiationEvent.getDefault());

executor.runDueTasks();
pipeline.remove(clientSdsHandler);
channel.runPendingTasks();
channel.checkException();
CommonCertProviderTestUtils.register0();
}

private static final class FakeGrpcHttp2ConnectionHandler extends GrpcHttp2ConnectionHandler {

FakeGrpcHttp2ConnectionHandler(
Expand Down