googleapis / java-pubsub

Apache License 2.0
128 stars 90 forks source link

Runtime error with PubSub Java client latest version 1.123.13 #1615

Closed NuwanSameera closed 1 year ago

NuwanSameera commented 1 year ago

I have a maven project with pubsub and I use maven-assembly-plugin to generate a jar file with dependencies.

With pubsub version 1.104.1, the jar file is working properly and I tried to update it to latest version 1.123.13. After updating, my application works as expected with exec-maven-plugin, but the same code is not working with a maven-assembly-plugin-generated jar file.

POM file and Error as follows.

<?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">

4.0.0
    <groupId>org.example</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>8</java.version>
        <junit-version>4.4</junit-version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-pubsub</artifactId>
            <version>1.123.13</version>
        </dependency>

    </dependencies>

    <build>

        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.5.0.Final</version>
            </extension>
        </extensions>

        <plugins>

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>Main</mainClass>
                        </manifest>
                    </archive>
                    <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>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.6.0</version>
                    <configuration>
                        <cleanupDaemonThreads>false</cleanupDaemonThreads>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>3.7.0.1746</version>
                </plugin>
            </plugins>
        </pluginManagement>

    </build>

</project>

Error Log

Jun 13, 2023 12:15:11 PM io.grpc.internal.ManagedChannelImpl$2 uncaughtException
        SEVERE: [Channel<3>: (pubsub.googleapis.com:443)] Uncaught exception in the SynchronizationContext. Panic!
        java.lang.IllegalStateException: Could not find policy 'pick_first'. Make sure its implementation is either registered to LoadBalancerRegistry or included in META-INF/services/io.grpc.LoadBalancerProvider from your jar files.
                at io.grpc.internal.AutoConfiguredLoadBalancerFactory$AutoConfiguredLoadBalancer.<init>(AutoConfiguredLoadBalancerFactory.java:94)
                at io.grpc.internal.AutoConfiguredLoadBalancerFactory.newLoadBalancer(AutoConfiguredLoadBalancerFactory.java:61)
                at io.grpc.internal.ManagedChannelImpl.exitIdleMode(ManagedChannelImpl.java:413)
                at io.grpc.internal.ManagedChannelImpl$RealChannel$2.run(ManagedChannelImpl.java:968)
                at io.grpc.SynchronizationContext.drain(SynchronizationContext.java:95)
                at io.grpc.SynchronizationContext.execute(SynchronizationContext.java:127)
                at io.grpc.internal.ManagedChannelImpl$RealChannel.newCall(ManagedChannelImpl.java:965)
                at com.google.api.gax.grpc.GrpcChannelUUIDInterceptor.interceptCall(GrpcChannelUUIDInterceptor.java:52)
                at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:156)
                at com.google.api.gax.grpc.GrpcHeaderInterceptor.interceptCall(GrpcHeaderInterceptor.java:80)
                at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:156)
                at com.google.api.gax.grpc.GrpcMetadataHandlerInterceptor.interceptCall(GrpcMetadataHandlerInterceptor.java:54)
                at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:156)
                at io.grpc.internal.ManagedChannelImpl.newCall(ManagedChannelImpl.java:907)
                at io.grpc.internal.ForwardingManagedChannel.newCall(ForwardingManagedChannel.java:63)
                at com.google.api.gax.grpc.ChannelPool$AffinityChannel.newCall(ChannelPool.java:516)
                at com.google.api.gax.grpc.ChannelPool.newCall(ChannelPool.java:145)
                at com.google.api.gax.grpc.GrpcClientCalls.newCall(GrpcClientCalls.java:99)
                at com.google.api.gax.grpc.GrpcDirectCallable.futureCall(GrpcDirectCallable.java:60)
                at com.google.api.gax.grpc.GrpcUnaryRequestParamCallable.futureCall(GrpcUnaryRequestParamCallable.java:65)
                at com.google.api.gax.grpc.GrpcExceptionCallable.futureCall(GrpcExceptionCallable.java:64)
                at com.google.api.gax.rpc.AttemptCallable.call(AttemptCallable.java:87)
                at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:63)
                at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:41)
                at com.google.api.gax.tracing.TracedUnaryCallable.futureCall(TracedUnaryCallable.java:75)
                at com.google.api.gax.rpc.UnaryCallable$1.futureCall(UnaryCallable.java:126)
                at com.google.api.gax.rpc.UnaryCallable.futureCall(UnaryCallable.java:87)
                at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112)
                at com.google.cloud.pubsub.v1.TopicAdminClient.createTopic(TopicAdminClient.java:319)
                at com.google.cloud.pubsub.v1.TopicAdminClient.createTopic(TopicAdminClient.java:224)
                at com.stl.sciocardio.common.pubsub.PubSubConsumer.createTopic(PubSubConsumer.java:232)
                at com.stl.sciocardio.common.pubsub.PubSubConsumer.startConsume(PubSubConsumer.java:197)
                at com.stl.sciocardio.common.pubsub.PubSubConsumer.run(PubSubConsumer.java:138)
                at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
                at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
                at java.base/java.lang.Thread.run(Thread.java:830)

        Exception in thread "pool-1-thread-1" com.google.api.gax.rpc.InternalException: io.grpc.StatusRuntimeException: INTERNAL: Panic! This is a bug!
                at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:110)
                at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:41)
                at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:86)
                at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:66)
                at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:97)
                at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:84)
                at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1132)
                at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:31)
                at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1270)
                at com.google.common.util.concurrent.AbstractFuture.addListener(AbstractFuture.java:761)
                at com.google.common.util.concurrent.ForwardingListenableFuture.addListener(ForwardingListenableFuture.java:47)
                at com.google.api.core.ApiFutureToListenableFuture.addListener(ApiFutureToListenableFuture.java:49)
                at com.google.common.util.concurrent.Futures.addCallback(Futures.java:1105)
                at com.google.api.core.ApiFutures.addCallback(ApiFutures.java:79)
                at com.google.api.gax.grpc.GrpcExceptionCallable.futureCall(GrpcExceptionCallable.java:67)
                at com.google.api.gax.rpc.AttemptCallable.call(AttemptCallable.java:87)
                at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:63)
                at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:41)
                at com.google.api.gax.tracing.TracedUnaryCallable.futureCall(TracedUnaryCallable.java:75)
                at com.google.api.gax.rpc.UnaryCallable$1.futureCall(UnaryCallable.java:126)
                at com.google.api.gax.rpc.UnaryCallable.futureCall(UnaryCallable.java:87)
                at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112)
                at com.google.cloud.pubsub.v1.TopicAdminClient.createTopic(TopicAdminClient.java:319)
                at com.google.cloud.pubsub.v1.TopicAdminClient.createTopic(TopicAdminClient.java:224)
                at com.stl.sciocardio.common.pubsub.PubSubConsumer.createTopic(PubSubConsumer.java:232)
                at com.stl.sciocardio.common.pubsub.PubSubConsumer.startConsume(PubSubConsumer.java:197)
                at com.stl.sciocardio.common.pubsub.PubSubConsumer.run(PubSubConsumer.java:138)
                at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
                at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
                at java.base/java.lang.Thread.run(Thread.java:830)
                Suppressed: com.google.api.gax.rpc.AsyncTaskException: Asynchronous task failed
                        at com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:57)
                        ... 9 more
        Caused by: io.grpc.StatusRuntimeException: INTERNAL: Panic! This is a bug!
                at io.grpc.Status.asRuntimeException(Status.java:539)
                at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:544)
                at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
                at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
                at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
                at com.google.api.gax.grpc.ChannelPool$ReleasingClientCall$1.onClose(ChannelPool.java:541)
                at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:567)
                at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:71)
                at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:735)
                at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:716)
                at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
                at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
                ... 3 more
        Caused by: java.lang.IllegalStateException: Could not find policy 'pick_first'. Make sure its implementation is either registered to LoadBalancerRegistry or included in META-INF/services/io.grpc.LoadBalancerProvider from your jar files.
                at io.grpc.internal.AutoConfiguredLoadBalancerFactory$AutoConfiguredLoadBalancer.<init>(AutoConfiguredLoadBalancerFactory.java:94)
                at io.grpc.internal.AutoConfiguredLoadBalancerFactory.newLoadBalancer(AutoConfiguredLoadBalancerFactory.java:61)
                at io.grpc.internal.ManagedChannelImpl.exitIdleMode(ManagedChannelImpl.java:413)
                at io.grpc.internal.ManagedChannelImpl$RealChannel$2.run(ManagedChannelImpl.java:968)
                at io.grpc.SynchronizationContext.drain(SynchronizationContext.java:95)
                at io.grpc.SynchronizationContext.execute(SynchronizationContext.java:127)
                at io.grpc.internal.ManagedChannelImpl$RealChannel.newCall(ManagedChannelImpl.java:965)
                at com.google.api.gax.grpc.GrpcChannelUUIDInterceptor.interceptCall(GrpcChannelUUIDInterceptor.java:52)
                at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:156)
                at com.google.api.gax.grpc.GrpcHeaderInterceptor.interceptCall(GrpcHeaderInterceptor.java:80)
                at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:156)
                at com.google.api.gax.grpc.GrpcMetadataHandlerInterceptor.interceptCall(GrpcMetadataHandlerInterceptor.java:54)
                at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:156)
                at io.grpc.internal.ManagedChannelImpl.newCall(ManagedChannelImpl.java:907)
                at io.grpc.internal.ForwardingManagedChannel.newCall(ForwardingManagedChannel.java:63)
                at com.google.api.gax.grpc.ChannelPool$AffinityChannel.newCall(ChannelPool.java:516)
                at com.google.api.gax.grpc.ChannelPool.newCall(ChannelPool.java:145)
                at com.google.api.gax.grpc.GrpcClientCalls.newCall(GrpcClientCalls.java:99)
                at com.google.api.gax.grpc.GrpcDirectCallable.futureCall(GrpcDirectCallable.java:60)
                at com.google.api.gax.grpc.GrpcUnaryRequestParamCallable.futureCall(GrpcUnaryRequestParamCallable.java:65)
                at com.google.api.gax.grpc.GrpcExceptionCallable.futureCall(GrpcExceptionCallable.java:64)
                at com.google.api.gax.rpc.AttemptCallable.call(AttemptCallable.java:87)
                at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:63)
                at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:41)
                at com.google.api.gax.tracing.TracedUnaryCallable.futureCall(TracedUnaryCallable.java:75)
                at com.google.api.gax.rpc.UnaryCallable$1.futureCall(UnaryCallable.java:126)
                at com.google.api.gax.rpc.UnaryCallable.futureCall(UnaryCallable.java:87)
                at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112)
                at com.google.cloud.pubsub.v1.TopicAdminClient.createTopic(TopicAdminClient.java:319)
                at com.google.cloud.pubsub.v1.TopicAdminClient.createTopic(TopicAdminClient.java:224)
                at com.stl.sciocardio.common.pubsub.PubSubConsumer.createTopic(PubSubConsumer.java:232)
                at com.stl.sciocardio.common.pubsub.PubSubConsumer.startConsume(PubSubConsumer.java:197)
                at com.stl.sciocardio.common.pubsub.PubSubConsumer.run(PubSubConsumer.java:138)
                ... 3 more

Dependency tree

[INFO] +- com.google.cloud:google-cloud-pubsub:jar:1.123.13:compile
[INFO] |  +- io.grpc:grpc-api:jar:1.55.1:compile
[INFO] |  +- io.grpc:grpc-context:jar:1.55.1:compile
[INFO] |  +- io.grpc:grpc-stub:jar:1.55.1:compile
[INFO] |  +- io.grpc:grpc-protobuf:jar:1.55.1:compile
[INFO] |  +- io.grpc:grpc-protobuf-lite:jar:1.55.1:compile
[INFO] |  +- com.google.api:api-common:jar:2.11.1:compile
[INFO] |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  +- com.google.protobuf:protobuf-java:jar:3.23.1:compile
[INFO] |  +- com.google.api.grpc:proto-google-common-protos:jar:2.19.1:compile
[INFO] |  +- com.google.auth:google-auth-library-oauth2-http:jar:1.16.0:compile
[INFO] |  +- com.google.auth:google-auth-library-credentials:jar:1.16.0:compile
[INFO] |  +- com.google.http-client:google-http-client-gson:jar:1.43.1:compile
[INFO] |  +- com.google.api.grpc:proto-google-cloud-pubsub-v1:jar:1.105.13:compile
[INFO] |  +- com.google.api.grpc:proto-google-iam-v1:jar:1.14.1:compile
[INFO] |  +- com.google.guava:guava:jar:31.1-jre:compile
[INFO] |  +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] |  +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] |  +- org.checkerframework:checker-qual:jar:3.32.0:compile
[INFO] |  +- com.google.j2objc:j2objc-annotations:jar:1.3:compile
[INFO] |  +- com.google.api:gax:jar:2.28.1:compile
[INFO] |  +- com.google.api:gax-grpc:jar:2.28.1:compile
[INFO] |  +- io.grpc:grpc-alts:jar:1.55.1:compile
[INFO] |  +- io.grpc:grpc-grpclb:jar:1.55.1:compile
[INFO] |  +- org.conscrypt:conscrypt-openjdk-uber:jar:2.5.2:compile
[INFO] |  +- io.grpc:grpc-auth:jar:1.55.1:compile
[INFO] |  +- io.grpc:grpc-netty-shaded:jar:1.55.1:compile
[INFO] |  +- io.grpc:grpc-googleapis:jar:1.55.1:runtime
[INFO] |  +- io.grpc:grpc-xds:jar:1.55.1:runtime
[INFO] |  +- io.opencensus:opencensus-proto:jar:0.2.0:runtime
[INFO] |  +- io.grpc:grpc-services:jar:1.55.1:runtime
[INFO] |  +- com.google.re2j:re2j:jar:1.6:runtime
[INFO] |  +- com.google.api:gax-httpjson:jar:0.113.1:compile
[INFO] |  +- com.google.code.gson:gson:jar:2.10.1:compile
[INFO] |  +- com.google.protobuf:protobuf-java-util:jar:3.23.1:compile
[INFO] |  +- org.threeten:threetenbp:jar:1.6.8:compile
[INFO] |  +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] |  +- io.opencensus:opencensus-api:jar:0.31.1:compile
[INFO] |  +- io.grpc:grpc-core:jar:1.55.1:compile
[INFO] |  +- com.google.android:annotations:jar:4.1.1.4:runtime
[INFO] |  +- org.codehaus.mojo:animal-sniffer-annotations:jar:1.23:runtime
[INFO] |  +- io.perfmark:perfmark-api:jar:0.26.0:runtime
[INFO] |  +- com.google.errorprone:error_prone_annotations:jar:2.18.0:compile
[INFO] |  +- com.google.auto.value:auto-value-annotations:jar:1.10.1:compile
[INFO] |  +- com.google.http-client:google-http-client:jar:1.43.1:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.5.14:runtime
[INFO] |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.15:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.16:runtime
[INFO] |  \- io.opencensus:opencensus-contrib-http-util:jar:0.31.1:compile
[INFO] +- com.google.cloud:google-cloud-nio:jar:0.125.0:compile
[INFO] |  +- com.google.cloud:google-cloud-storage:jar:2.16.0:compile
[INFO] |  |  +- com.google.http-client:google-http-client-jackson2:jar:1.42.3:compile
[INFO] |  |  +- com.google.api-client:google-api-client:jar:2.1.1:compile
[INFO] |  |  +- com.google.oauth-client:google-oauth-client:jar:1.34.1:compile
[INFO] |  |  +- com.google.http-client:google-http-client-apache-v2:jar:1.42.3:compile
[INFO] |  |  +- com.google.cloud:google-cloud-core-http:jar:2.9.0:compile
[INFO] |  |  +- com.google.http-client:google-http-client-appengine:jar:1.42.3:compile
[INFO] |  |  +- com.google.cloud:google-cloud-core-grpc:jar:2.9.0:compile
[INFO] |  |  +- com.google.api.grpc:proto-google-cloud-storage-v2:jar:2.16.0-alpha:compile
[INFO] |  |  +- com.google.api.grpc:grpc-google-cloud-storage-v2:jar:2.16.0-alpha:compile
[INFO] |  |  +- com.google.api.grpc:gapic-google-cloud-storage-v2:jar:2.16.0-alpha:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-core:jar:2.14.1:compile
[INFO] |  |  \- com.google.api.grpc:grpc-google-iam-v1:jar:1.6.22:compile
[INFO] |  +- com.google.apis:google-api-services-storage:jar:v1-rev20220705-2.0.0:compile
[INFO] |  +- com.google.cloud:google-cloud-core:jar:2.9.0:compile
[INFO] |  \- javax.inject:javax.inject:jar:1:compile
[INFO] \- org.postgresql:postgresql:jar:42.3.1:compile
maitrimangal commented 1 year ago

Hi perhaps try adding this in to your build.gradle?

shadowJar { mergeServiceFiles() }

Found from this thread- https://github.com/grpc/grpc-java/issues/5493#issuecomment-478500418

NuwanSameera commented 1 year ago

@maitrimangal thank you very much for your answer. I resolved it with maven shade plugin and service files merge transform.

Added detailed answer to my question in https://stackoverflow.com/a/76478906/5607943