Error with building io.grpc.ManagedChannelRegistry

494 views
Skip to first unread message

Akash Sinha

unread,
May 22, 2024, 12:03:43 PM5/22/24
to grpc.io
Hello Everyone, 

I am trying to build a JAVA based gRPC client that tries to communicate with Python based gRPC server. I am getting the following exception when I run the code from terminal using the JAR file.  

Exception in thread "main" io.grpc.ManagedChannelRegistry$ProviderNotFoundException: io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider: does not support 1 or more of [class io.grpc.netty.shaded.io.netty.channel.unix.DomainSocketAddress]

at io.grpc.ManagedChannelRegistry.newChannelBuilder(ManagedChannelRegistry.java:204)

at io.grpc.ManagedChannelRegistry.newChannelBuilder(ManagedChannelRegistry.java:155)

at io.grpc.Grpc.newChannelBuilder(Grpc.java:101)

The error happens while executing the following code: 

String target = "localhost:"+port;

ManagedChannel channel = Grpc.newChannelBuilder(target, InsecureChannelCredentials.create()).build(); 

However, the code runs fine when running the main class from the IDE. I have created the fat jar file using maven. Following is my pom.xml file. 

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>DummyEnv</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.63.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.63.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.63.0</version>
</dependency>
<dependency> <!-- necessary for Java 9+ -->
<groupId>org.apache.tomcat</groupId>
<artifactId>annotations-api</artifactId>
<version>6.0.53</version>
<scope>provided</scope>
</dependency>


</dependencies>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.7.1</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.25.1:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.63.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Can someone please help me in debugging this issue? 

Thanks :) 

Kannan Jayaprakasam

unread,
May 28, 2024, 12:21:16 PM5/28/24
to grpc.io
In io.grpc.internal.ManagedChannelImplBuilder it does a
  provider = nameResolverRegistry.getProviderForScheme(targetUri.getScheme());
The NameResolverRegistry has 2 entries when I tried with localhost url: "dns" -> DnsNameResolverProvider and "unix" -> UdsNameResolverProvider.

For localhost java.net.URI getScheme will return null so the ManagedChannelImplBuilder will fallback to the default scheme. The default scheme is taken from the name resolver provider with the highest priority which is DnsNameResolverProvider in this case, whose scheme is dns.
In your case when you run from the command line apparently only the UdsNameResolverProvider gets registered but not the DnsNameResolverProvider, and produces a socket address type not supported by Netty.

Can you run with fine logging enabled so that it prints why a name resolver provider could not be loaded here?

Eric Anderson

unread,
May 28, 2024, 12:26:40 PM5/28/24
to Akash Sinha, grpc.io, Kannan Jayaprakasam
The problem here is maven-assembly-plugin breaks SPI "services," because by default it fails to combine some magic files together. This causes the dns name resolver to not be found, and can prevent some transports and load balancers also to not be found.

You need to configure it to use the metaInf-services handler. See https://stackoverflow.com/a/49689041/4690866 (you can ignore the metaInf-spring and plexus parts).

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/4ab9aa81-5fb5-4176-91eb-298ee6e55dbcn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages