Skip to content

CompositeGrpcChannelFactory identifies default inprocess target as supported by factories other than InProcessGrpcChannelFactory #342

@cengdall-blaze

Description

@cengdall-blaze

As part of identifying the appropriate factory to use for a given target, CompositeGrpcChannelFactory finds the first factory for which supports(target) returns true.

@Override
	public ManagedChannel createChannel(final String target, ChannelBuilderOptions options) {
		return this.channelFactories.stream()
			.filter((cf) -> cf.supports(target))
			.findFirst()
			.orElseThrow(
					() -> new IllegalStateException("No grpc channel factory found that supports target : " + target))
			.createChannel(target, options);
	}

When the target is the default channel configured via application properties, target in the above method will evaluate to default. If the default channel address has been prefixed with in-process, the above code incorrectly identifies target as being supported by factories other than InProcessGrpcChannelFactory.

grpc:
    client:
      default-channel:
        address: in-process:test

As a result, the createChannel call ultimately fails with an IllegalArgumentException due to having an invalid DNS name.

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Object]: Factory method 'getClient' threw exception with message: Invalid DNS name: in-process:test
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.lambda$instantiate$0(SimpleInstantiationStrategy.java:183)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiateWithFactoryMethod(SimpleInstantiationStrategy.java:72)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:152)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
	... 39 more
Caused by: java.lang.IllegalArgumentException: Invalid DNS name: in-process:test
	at com.google.common.base.Preconditions.checkArgument(Preconditions.java:217)
	at io.grpc.internal.DnsNameResolver.<init>(DnsNameResolver.java:168)
	at io.grpc.internal.DnsNameResolverProvider.newNameResolver(DnsNameResolverProvider.java:64)
	at io.grpc.internal.ManagedChannelImpl.getNameResolver(ManagedChannelImpl.java:682)
	at io.grpc.internal.ManagedChannelImpl.<init>(ManagedChannelImpl.java:605)
	at io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:731)
	at io.grpc.ForwardingChannelBuilder2.build(ForwardingChannelBuilder2.java:278)
	at org.springframework.grpc.client.DefaultGrpcChannelFactory.createChannel(DefaultGrpcChannelFactory.java:120)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions