mirror of https://github.com/grpc/grpc-java.git
core: permanently store authority at channel creation (#4886)
Getting the authority must not rely on the name resolver being non-null, because that can trivially happen if the channel is shut down.
This commit is contained in:
parent
8b16899bc1
commit
2fae9a3a97
|
|
@ -576,7 +576,7 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
||||||
this.retryEnabled = builder.retryEnabled && !builder.temporarilyDisableRetry;
|
this.retryEnabled = builder.retryEnabled && !builder.temporarilyDisableRetry;
|
||||||
serviceConfigInterceptor = new ServiceConfigInterceptor(
|
serviceConfigInterceptor = new ServiceConfigInterceptor(
|
||||||
retryEnabled, builder.maxRetryAttempts, builder.maxHedgedAttempts);
|
retryEnabled, builder.maxRetryAttempts, builder.maxHedgedAttempts);
|
||||||
Channel channel = new RealChannel();
|
Channel channel = new RealChannel(nameResolver.getServiceAuthority());
|
||||||
channel = ClientInterceptors.intercept(channel, serviceConfigInterceptor);
|
channel = ClientInterceptors.intercept(channel, serviceConfigInterceptor);
|
||||||
if (builder.binlog != null) {
|
if (builder.binlog != null) {
|
||||||
channel = builder.binlog.wrapChannel(channel);
|
channel = builder.binlog.wrapChannel(channel);
|
||||||
|
|
@ -810,6 +810,14 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RealChannel extends Channel {
|
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
|
@Override
|
||||||
public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method,
|
public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method,
|
||||||
CallOptions callOptions) {
|
CallOptions callOptions) {
|
||||||
|
|
@ -828,8 +836,7 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String authority() {
|
public String authority() {
|
||||||
String authority = nameResolver.getServiceAuthority();
|
return authority;
|
||||||
return checkNotNull(authority, "authority");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2801,6 +2801,14 @@ public class ManagedChannelImplTest {
|
||||||
mychannel.shutdownNow();
|
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
|
private static final class ChannelBuilder
|
||||||
extends AbstractManagedChannelImplBuilder<ChannelBuilder> {
|
extends AbstractManagedChannelImplBuilder<ChannelBuilder> {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue