maestro icon indicating copy to clipboard operation
maestro copied to clipboard

Android Driver - io.grpc.StatusRuntimeException: UNAVAILABLE: io exception

Open pezzeonline opened this issue 1 year ago • 17 comments

I used Maestro in the past but since some months Maestro is not longer working on more than one Macbook with ARM M1.

Test already done without success:

  • installing latest version using cURL
  • installing latest version using Brew
  • installing older version using cURL
  • tested on more than one physical phone

Maestro is working only on emulator.

Here it is a log of maestro studio (but it is the same with maestro test):

~ maestro studio
Running on d543e0800404

╭────────────────────────────────────────────────────────╮
│                                                        │
│   Maestro Studio is running at http://localhost:9999   │
│                                                        │
╰────────────────────────────────────────────────────────╯


Tip: Maestro Studio can now run simultaneously alongside other Maestro CLI commands!

Navigate to http://localhost:9999 in your browser to open Maestro Studio. Ctrl-C to exit.
io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
	at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:271)
	at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:252)
	at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:165)
	at maestro_android.MaestroDriverGrpc$MaestroDriverBlockingStub.deviceInfo(MaestroDriverGrpc.java:475)
	at maestro.drivers.AndroidDriver.deviceInfo(AndroidDriver.kt:159)
	at maestro.ViewHierarchy$Companion.from-c1iYVAs(ViewHierarchy.kt:28)
	at maestro.Maestro.viewHierarchy-prqvCes(Maestro.kt:372)
	at maestro.studio.DeviceScreenService$routes$1.invokeSuspend(DeviceScreenService.kt:41)
	at maestro.studio.DeviceScreenService$routes$1.invoke(DeviceScreenService.kt)
	at maestro.studio.DeviceScreenService$routes$1.invoke(DeviceScreenService.kt)
	at io.ktor.server.routing.Route$buildPipeline$1$1.invokeSuspend(Route.kt:116)
	at io.ktor.server.routing.Route$buildPipeline$1$1.invoke(Route.kt)
	at io.ktor.server.routing.Route$buildPipeline$1$1.invoke(Route.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
	at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:98)
	at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
	at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
	at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
	at io.ktor.server.routing.Routing.executeResult(Routing.kt:190)
	at io.ktor.server.routing.Routing.interceptor(Routing.kt:64)
	at io.ktor.server.routing.Routing$Plugin$install$1.invokeSuspend(Routing.kt:140)
	at io.ktor.server.routing.Routing$Plugin$install$1.invoke(Routing.kt)
	at io.ktor.server.routing.Routing$Plugin$install$1.invoke(Routing.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
	at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invokeSuspend(BaseApplicationEngine.kt:123)
	at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invoke(BaseApplicationEngine.kt)
	at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invoke(BaseApplicationEngine.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
	at io.ktor.server.application.hooks.CallFailed$install$1$1.invokeSuspend(CommonHooks.kt:43)
	at io.ktor.server.application.hooks.CallFailed$install$1$1.invoke(CommonHooks.kt)
	at io.ktor.server.application.hooks.CallFailed$install$1$1.invoke(CommonHooks.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
	at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
	at io.ktor.server.application.hooks.CallFailed$install$1.invokeSuspend(CommonHooks.kt:42)
	at io.ktor.server.application.hooks.CallFailed$install$1.invoke(CommonHooks.kt)
	at io.ktor.server.application.hooks.CallFailed$install$1.invoke(CommonHooks.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
	at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:98)
	at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invokeSuspend(DefaultEnginePipeline.kt:118)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invoke(DefaultEnginePipeline.kt)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invoke(DefaultEnginePipeline.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
	at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:98)
	at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
	at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1$invokeSuspend$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
	at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
	at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invokeSuspend(NettyApplicationCallHandler.kt:119)
	at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invoke(NettyApplicationCallHandler.kt)
	at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invoke(NettyApplicationCallHandler.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:55)
	at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:112)
	at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
	at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
	at io.ktor.server.netty.NettyApplicationCallHandler.handleRequest(NettyApplicationCallHandler.kt:37)
	at io.ktor.server.netty.NettyApplicationCallHandler.channelRead(NettyApplicationCallHandler.kt:29)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
	at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:61)
	at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:425)
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.ktor.server.netty.EventLoopGroupProxy$Companion.create$lambda$1$lambda$0(NettyApplicationEngine.kt:291)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/0:0:0:0:0:0:0:1:7001
Caused by: java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:777)
	at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337)
	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:829)
io.grpc.StatusRuntimeException: UNAVAILABLE: io exception

pezzeonline avatar Apr 17 '23 16:04 pezzeonline

With my Macbook Pro(M1 Pro) currently - I have an issue with connecting physical devices but with the emulator, it's working.

Previously(before a few months) it's worked for me on my old Macbook Air(M1) with the device as well.

Personally, I don't think it's M1 - maybe some configuration or something similar. If anyone has an idea to get this fixed it would be very much helpful.

JigneshWorld avatar Apr 20 '23 04:04 JigneshWorld

Personally, I don't think it's M1 - maybe some configuration or something similar. If anyone has an idea to get this fixed it would be very much helpful.

Exactly, I've used maestro on m1 months ago and it worked. Now it seems not working anymore even if I try old releases.

pezzeonline avatar Apr 20 '23 07:04 pezzeonline

This indeed doesn't seem related to M1 MacBooks, because I use Maestro (test and studio) daily on an M1.

@pezzeonline can you check if there is some process running on 7001 port that would block the connection?

felipevolpone avatar Apr 24 '23 14:04 felipevolpone

This indeed doesn't seem related to M1 MacBooks, because I use Maestro (test and studio) daily on an M1.

@pezzeonline can you check if there is some process running on 7001 port that would block the connection?

Tested and no process on 7001 port. I thought it was an M1 problem because I have the same error on 2 Mac M1 but it works on Intel.

The first time I execute maestro the error is:

➜  server git:(develop) ✗ maestro studio
Running on 968c6a2b0506

java.io.IOException: pm list packages --user 0 dev.mobile.maestro.test
	at maestro.drivers.AndroidDriver.shell(AndroidDriver.kt:773)
	at maestro.drivers.AndroidDriver.isPackageInstalled(AndroidDriver.kt:761)
	at maestro.drivers.AndroidDriver.uninstallMaestroApks(AndroidDriver.kt:736)
	at maestro.drivers.AndroidDriver.open(AndroidDriver.kt:90)
	at maestro.Maestro$Companion.android(Maestro.kt:534)
	at maestro.cli.session.MaestroSessionManager.createAndroid(MaestroSessionManager.kt:270)
	at maestro.cli.session.MaestroSessionManager.createMaestro(MaestroSessionManager.kt:151)
	at maestro.cli.session.MaestroSessionManager.access$createMaestro(MaestroSessionManager.kt:49)
	at maestro.cli.session.MaestroSessionManager$newSession$session$1.invoke(MaestroSessionManager.kt:81)
	at maestro.cli.session.MaestroSessionManager$newSession$session$1.invoke(MaestroSessionManager.kt:80)
	at maestro.cli.db.KeyValueStore.withExclusiveLock(KeyValueStore.kt:37)
	at maestro.cli.session.SessionStore.withExclusiveLock(SessionStore.kt:74)
	at maestro.cli.session.MaestroSessionManager.newSession(MaestroSessionManager.kt:80)
	at maestro.cli.command.StudioCommand.call(StudioCommand.kt:36)
	at maestro.cli.command.StudioCommand.call(StudioCommand.kt:18)
	at picocli.CommandLine.executeUserObject(CommandLine.java:1933)
	at picocli.CommandLine.access$1200(CommandLine.java:145)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2332)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2326)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2291)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2159)
	at maestro.cli.DisableAnsiMixin$Companion.executionStrategy(DisableAnsiMixin.kt:22)
	at picocli.CommandLine.execute(CommandLine.java:2058)
	at maestro.cli.AppKt.main(App.kt:125)
Caused by: java.io.IOException: Command failed (shell,v2,raw:pm list packages --user 0 dev.mobile.maestro.test): closed
	at dadb.adbserver.AdbServer.send$dadb(AdbServer.kt:99)
	at dadb.adbserver.AdbServerDadb.open(AdbServer.kt:138)
	at dadb.Dadb$DefaultImpls.openShell(Dadb.kt:43)
	at dadb.adbserver.AdbServerDadb.openShell(AdbServer.kt:118)
	at dadb.Dadb$DefaultImpls.shell(Dadb.kt:36)
	at dadb.adbserver.AdbServerDadb.shell(AdbServer.kt:118)
	at maestro.drivers.AndroidDriver.shell(AndroidDriver.kt:771)

And the second time is the error I've attached before.

pezzeonline avatar Apr 24 '23 15:04 pezzeonline

Heads up - Just updated the title of this issue as it seems to not be related specifically to M1s

Leland-Takamine avatar May 03 '23 15:05 Leland-Takamine

@pezzeonline : I am having the same problem on intel #1089, did you manage to solve the problem?

The version I tried is 1.28.0.

Angelk90 avatar May 20 '23 12:05 Angelk90

Unfortunatelly not. I've tried a lot of different versions without success.

pezzeonline avatar May 20 '23 14:05 pezzeonline

@pezzeonline : Even if I try to run the maestro bugreport command, it gives me no information.

@Leland-Takamine, @ArthurSav , @axelniklasson : Can you tell us what this could be due to?

From what we know so far it doesn't depend on the maestro version or even on the Intel/M1 version.

Angelk90 avatar May 29 '23 14:05 Angelk90

I am also experiencing this issue, out of the blue, with the latest version on Android only. It was working and then it stopped working. I have tried different emulators. Neither maestro studio nor maestro test are working. maestro bugreport generates an empty file. There are no processes running on port 7001.

MartaGalve avatar May 29 '23 19:05 MartaGalve

I just quit the terminal and launched it again and it started working...

MartaGalve avatar May 29 '23 19:05 MartaGalve

@MartaGalve : Did you install via brew or curl?

Angelk90 avatar May 29 '23 20:05 Angelk90

Using curl @Angelk90

MartaGalve avatar May 29 '23 23:05 MartaGalve

@MartaGalve : Is it currently working for you? Does it happen to you that it gets stuck, it says Running on ....? Then close and run the command again and then it works?

Angelk90 avatar May 30 '23 10:05 Angelk90

I just quit the terminal and launched it again and it started working...

This also seemed to fix the issue for me, yet I got the io exception when trying to run the tests and launching the app.

My app id starts with io.xyz which also might be related. When changing the appId in the flow.yaml file to com.xyz I all of a sudden got a different error when trying to run the tests- the error stated that the app was not installed.

(Un)fortunately, I can not reproduce it anymore

vanGalilea avatar Jun 14 '23 09:06 vanGalilea

@Angelk90 since I relaunched the terminal I have had no issues.

seaBubble avatar Jun 14 '23 09:06 seaBubble

I've been facing similar issues for some time now around android drive & grpc, this is really stumping our android CI as we can't just quit and restart.

This issue does seem similar to what I've found with the below issues, I believe all of these above are related to theio.grpc.StatusRuntimeException.

Below are what I've found to be all related in order of when I first found them:

  1. https://github.com/mobile-dev-inc/maestro/issues/1525
  2. https://github.com/mobile-dev-inc/maestro/issues/1570
  3. https://github.com/mobile-dev-inc/maestro/issues/1647

I've also noticed an android alert displays "System UI isn't responding" & also a secondary alert "Process system isn't responding" sometimes occur on the emulator/physical device when this grpc exception is thrown. Sometimes the android alert message doesn't show and the device become unresponsive, then suddenly become responsive after some time.

There is some issues raised around this grpc issue here also https://github.com/grpc/grpc-java/issues/10120

I'm on an Apple MacBook Pro M2 Max.

Hopefully these breadcrumbs might help solve this.

DavidREntwistle avatar Jan 22 '24 18:01 DavidREntwistle

last post is 100% on right path. This is about the gRPC stream between device and AndroidDriver

I noticed this on devices that had problem on RPC port, or low memory devices, or when I was working on Sharding feature involving the RPC port.

I think we need a stream handler that keeps the RPC connection active like a heartbeat function, constantly checking the connection in a safe way and gracefully reconnect when something interrupts it or times it out.

I genuinely think the flakes are caused by this.

@Leland-Takamine you can reproduce this by running many maestro instances until you run out of memory, and one of them will give up early and result in interrupting the gRPC stream causing this io exception.

I think this is exactly the problem - I might look into it after sharding is merged. 100% stable sessions would be great

sdfgsdfgd avatar May 09 '24 01:05 sdfgsdfgd

I'm running into the same issue for Android only on the latest maestro version (1.38.1) but not iOS. Previously listed workarounds (closing and restarting the terminal) did not help. Any ideas on how to debug/unblock this for Android testing?

navignaw avatar Sep 04 '24 23:09 navignaw