Skip to content
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
13 changes: 10 additions & 3 deletions core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ ClientStream newSubstream(ClientStreamTracer.Factory tracerFactory, Metadata new
this.retryEnabled = builder.retryEnabled && !builder.temporarilyDisableRetry;
serviceConfigInterceptor = new ServiceConfigInterceptor(
retryEnabled, builder.maxRetryAttempts, builder.maxHedgedAttempts);
Channel channel = new RealChannel();
Channel channel = new RealChannel(nameResolver.getServiceAuthority());
channel = ClientInterceptors.intercept(channel, serviceConfigInterceptor);
if (builder.binlog != null) {
channel = builder.binlog.wrapChannel(channel);
Expand Down Expand Up @@ -810,6 +810,14 @@ private Executor getCallExecutor(CallOptions callOptions) {
}

private class RealChannel extends Channel {
// Set when the NameResolver is initially created. When we create a new NameResolver for the
// same target, the new instance must have the same value.
private final String authority;

private RealChannel(String authority) {
this.authority = checkNotNull(authority, "authority");
}

@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method,
CallOptions callOptions) {
Expand All @@ -828,8 +836,7 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, Resp

@Override
public String authority() {
String authority = nameResolver.getServiceAuthority();
return checkNotNull(authority, "authority");
return authority;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2801,6 +2801,14 @@ protected ClientTransportFactory buildTransportFactory() {
mychannel.shutdownNow();
}

@Test
public void getAuthorityAfterShutdown() throws Exception {
createChannel();
assertEquals(SERVICE_NAME, channel.authority());
channel.shutdownNow().awaitTermination(1, TimeUnit.SECONDS);
assertEquals(SERVICE_NAME, channel.authority());
}

private static final class ChannelBuilder
extends AbstractManagedChannelImplBuilder<ChannelBuilder> {

Expand Down