Skip to content

Commit 6ee4184

Browse files
sanjaypujareejona86
authored andcommitted
xds: handle the handlerRemoved callback to skip updateSslContext processing (#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.
1 parent aac837d commit 6ee4184

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

xds/src/main/java/io/grpc/xds/internal/security/SecurityProtocolNegotiators.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ protected void handlerAdded0(final ChannelHandlerContext ctx) {
209209

210210
@Override
211211
public void updateSslContext(SslContext sslContext) {
212+
if (ctx.isRemoved()) {
213+
return;
214+
}
212215
logger.log(
213216
Level.FINEST,
214217
"ClientSdsHandler.updateSslContext authority={0}, ctx.name={1}",

xds/src/test/java/io/grpc/xds/internal/security/SecurityProtocolNegotiatorsTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,36 @@ protected void onException(Throwable throwable) {
405405
CommonCertProviderTestUtils.register0();
406406
}
407407

408+
@Test
409+
public void clientSdsProtocolNegotiatorNewHandler_handleHandlerRemoved() {
410+
FakeClock executor = new FakeClock();
411+
CommonCertProviderTestUtils.register(executor);
412+
Bootstrapper.BootstrapInfo bootstrapInfoForClient = CommonBootstrapperTestUtils
413+
.buildBootstrapInfo("google_cloud_private_spiffe-client", CLIENT_KEY_FILE, CLIENT_PEM_FILE,
414+
CA_PEM_FILE, null, null, null, null);
415+
UpstreamTlsContext upstreamTlsContext =
416+
CommonTlsContextTestsUtil
417+
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true);
418+
419+
SslContextProviderSupplier sslContextProviderSupplier =
420+
new SslContextProviderSupplier(upstreamTlsContext,
421+
new TlsContextManagerImpl(bootstrapInfoForClient));
422+
SecurityProtocolNegotiators.ClientSdsHandler clientSdsHandler =
423+
new SecurityProtocolNegotiators.ClientSdsHandler(grpcHandler, sslContextProviderSupplier);
424+
425+
pipeline.addLast(clientSdsHandler);
426+
channelHandlerCtx = pipeline.context(clientSdsHandler);
427+
428+
// kick off protocol negotiation.
429+
pipeline.fireUserEventTriggered(InternalProtocolNegotiationEvent.getDefault());
430+
431+
executor.runDueTasks();
432+
pipeline.remove(clientSdsHandler);
433+
channel.runPendingTasks();
434+
channel.checkException();
435+
CommonCertProviderTestUtils.register0();
436+
}
437+
408438
private static final class FakeGrpcHttp2ConnectionHandler extends GrpcHttp2ConnectionHandler {
409439

410440
FakeGrpcHttp2ConnectionHandler(

0 commit comments

Comments
 (0)