Skip to content

Commit

Permalink
xds: handle the handlerRemoved callback to skip updateSslContext proc…
Browse files Browse the repository at this point in the history
…essing (#10118)

* xds: handle the handlerRemoved callback to skip updateSslContext processing
     In handlerAdded we submit a callback to updateSslContext but before the
     callback is executed the handler could be removed (e.g. bad connection)
     in which case the callback should skip all of the processing.
     Also added a unit test to check there is no exception.
  • Loading branch information
sanjaypujare authored and ejona86 committed May 3, 2023
1 parent aac837d commit 6ee4184
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ protected void handlerAdded0(final ChannelHandlerContext ctx) {

@Override
public void updateSslContext(SslContext sslContext) {
if (ctx.isRemoved()) {
return;
}
logger.log(
Level.FINEST,
"ClientSdsHandler.updateSslContext authority={0}, ctx.name={1}",
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

0 comments on commit 6ee4184

Please sign in to comment.