Android GRPC client http call error io.grpc.StatusException: UNAVAILABLE: End of stream or IOException

Viewed 789

Grettings,

I like to know about how to ressolve the following exception when calling a GRPC service built with NodeJS in the backend side, and deployed to internet using Repl.it. The following is the message that i got during the ui tests:

 io.grpc.StatusException: UNAVAILABLE: End of stream or IOException
        at io.grpc.Status.asException(Status.java:550)
        at io.grpc.kotlin.ClientCalls$rpcImpl$1$1$1.onClose(ClientCalls.kt:289)
        at io.grpc.internal.DelayedClientCall$DelayedListener$3.run(DelayedClientCall.java:464)
        at io.grpc.internal.DelayedClientCall$DelayedListener.delayOrExecute(DelayedClientCall.java:428)
        at io.grpc.internal.DelayedClientCall$DelayedListener.onClose(DelayedClientCall.java:461)
        at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:553)
        at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:68)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:739)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:718)
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)

##Context: ## Im currently working in an android application and i tried to implement GRPC features in backend and the mobile client, in the Android side, i've setup the grpc client using the protobuf-gradle-plugin, libraries such as grpc-stub,grpc-java,grpc-kotlin, and the protobuff plugin that exists in Android studio.

The mentioned gradle plugin and the libraries have generated the client classes for the proto file, and for the backend side, i've implemented the grpc service using the official libraries for that, ensuring that the service is exposed using 0.0.0.0 and it works when connecting to it using a nodejs client.

/* grpc server service setup and running */

/* ... definitions and proto file loading ... */

function main() {
    let server = new grpc.Server();
    server.addService(placesProto.PlacesService.service, {
      List: placesEndpoint.List
    });
    server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
    server.start();
        console.log('grpc server running at {0.0.0.0:50051}');
}

main();
/* remote data source using the generated grpc service client*/
class DataSource {
        private val channel: ManagedChannel =
            ManagedChannelBuilder.forAddress(BuildConfig.GRPC_API_HOSTNAME, BuildConfig.GRPC_API_PORT)
                .idleTimeout(30, TimeUnit.SECONDS).usePlaintext().build()

        private val client: PlacesServiceGrpcKt.PlacesServiceCoroutineStub =
            PlacesServiceGrpcKt.PlacesServiceCoroutineStub(channel)

        suspend fun fetchPlaces(): Flow<AppResult<List<VisitablePlace>>> = flow {
            val response: PlacesListResponse = client.list(PlacesListRequest.getDefaultInstance())
            emit(when {
                response.placesList.isNotEmpty() -> {
                    val visitablePlaces: List<VisitablePlace> =
                        response.placesList.mapNotNull { VisitablePlace(it) }
                    AppResult.Success(visitablePlaces)
                }
                else -> {
                    AppResult.Error(Exception("Places list not available."))
                }
            })
        }
    }

Worth to mention:

  • Im using Repl.it for the nodejs backend, because of the ease of developing and serving web apps from there, in that part, i've tested the service using javascript from there, the idea is to know about how to address the connection between them, in kotlin code snippet, im using the provided classes from the grpc client libraries :S
  • im doing the tests using a physical device (not emulator)

Best regards,

0 Answers
Related