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

core: ManagedChannelImpl to always use RetryingNameResolver #10328

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,6 @@ static NameResolver getNameResolver(
String target, @Nullable final String overrideAuthority,
NameResolver.Factory nameResolverFactory, NameResolver.Args nameResolverArgs) {
NameResolver resolver = getNameResolver(target, nameResolverFactory, nameResolverArgs);
if (overrideAuthority == null) {
return resolver;
}

// If the nameResolver is not already a RetryingNameResolver, then wrap it with it.
// This helps guarantee that name resolution retry remains supported even as it has been
Expand All @@ -769,6 +766,10 @@ static NameResolver getNameResolver(
nameResolverArgs.getSynchronizationContext());
}

if (overrideAuthority == null) {
return usedNameResolver;
}

return new ForwardingNameResolver(usedNameResolver) {
@Override
public String getServiceAuthority() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ public String getDefaultScheme() {

private void testValidTarget(String target, String expectedUriString, URI expectedUri) {
NameResolver.Factory nameResolverFactory = new FakeNameResolverFactory(expectedUri.getScheme());
FakeNameResolver nameResolver = (FakeNameResolver) ManagedChannelImpl.getNameResolver(
target, null, nameResolverFactory, NAMERESOLVER_ARGS);
FakeNameResolver nameResolver
= (FakeNameResolver) ((RetryingNameResolver) ManagedChannelImpl.getNameResolver(
target, null, nameResolverFactory, NAMERESOLVER_ARGS)).getRetriedNameResolver();
assertNotNull(nameResolver);
assertEquals(expectedUri, nameResolver.uri);
assertEquals(expectedUriString, nameResolver.uri.toString());
Expand Down
27 changes: 17 additions & 10 deletions core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ public String getPolicyName() {
ArgumentCaptor.forClass(ClientStreamListener.class);

private void createChannel(ClientInterceptor... interceptors) {
createChannel(false, interceptors);
}

private void createChannel(boolean nameResolutionExpectedToFail,
ClientInterceptor... interceptors) {
checkState(channel == null);

channel = new ManagedChannelImpl(
Expand All @@ -288,7 +293,7 @@ channelBuilder, mockTransportFactory, new FakeBackoffPolicyProvider(),
timer.getTimeProvider());

if (requestConnection) {
int numExpectedTasks = 0;
int numExpectedTasks = nameResolutionExpectedToFail ? 1 : 0;

// Force-exit the initial idle-mode
channel.syncContext.execute(new Runnable() {
Expand Down Expand Up @@ -3000,7 +3005,7 @@ public void channelTracing_nameResolvingErrorEvent() throws Exception {
FakeNameResolverFactory nameResolverFactory =
new FakeNameResolverFactory.Builder(expectedUri).setError(error).build();
channelBuilder.nameResolverFactory(nameResolverFactory);
createChannel();
createChannel(true);

assertThat(getStats(channel).channelTrace.events).contains(new ChannelTrace.Event.Builder()
.setDescription("Failed to resolve name: " + error)
Expand Down Expand Up @@ -3503,10 +3508,11 @@ public double nextDouble() {
ArgumentCaptor<Helper> helperCaptor = ArgumentCaptor.forClass(Helper.class);
verify(mockLoadBalancerProvider).newLoadBalancer(helperCaptor.capture());
helper = helperCaptor.getValue();
verify(mockLoadBalancer).acceptResolvedAddresses(
ResolvedAddresses.newBuilder()
.setAddresses(nameResolverFactory.servers)
.build());
verify(mockLoadBalancer).acceptResolvedAddresses(resolvedAddressCaptor.capture());
ResolvedAddresses resolvedAddresses = resolvedAddressCaptor.getValue();
assertThat(resolvedAddresses.getAddresses()).isEqualTo(nameResolverFactory.servers);
assertThat(resolvedAddresses.getAttributes()
.get(RetryingNameResolver.RESOLUTION_RESULT_LISTENER_KEY)).isNotNull();

// simulating request connection and then transport ready after resolved address
Subchannel subchannel =
Expand Down Expand Up @@ -3609,10 +3615,11 @@ public void hedgingScheduledThenChannelShutdown_hedgeShouldStillHappen_newCallSh
ArgumentCaptor<Helper> helperCaptor = ArgumentCaptor.forClass(Helper.class);
verify(mockLoadBalancerProvider).newLoadBalancer(helperCaptor.capture());
helper = helperCaptor.getValue();
verify(mockLoadBalancer).acceptResolvedAddresses(
ResolvedAddresses.newBuilder()
.setAddresses(nameResolverFactory.servers)
.build());
verify(mockLoadBalancer).acceptResolvedAddresses(resolvedAddressCaptor.capture());
ResolvedAddresses resolvedAddresses = resolvedAddressCaptor.getValue();
assertThat(resolvedAddresses.getAddresses()).isEqualTo(nameResolverFactory.servers);
assertThat(resolvedAddresses.getAttributes()
.get(RetryingNameResolver.RESOLUTION_RESULT_LISTENER_KEY)).isNotNull();

// simulating request connection and then transport ready after resolved address
Subchannel subchannel =
Expand Down