uiautomator2 - stopping and starting the script with out ending the session causes issue #7527

Closed
srkannan opened this Issue Dec 13, 2016 · 4 comments

Projects

None yet

5 participants

@srkannan

The problem

[MJSONWP] Encountered internal error running command: {"jsonwp":{"status":13,"value":"java.lang.IllegalThreadStateException: Thread already started\n\tat java.lang.Thread.checkNotStarted(Thread.java:849)\n\tat java.lang.Thread.start(Thread.java:1059)\n\tat io.appium.uiautomator2.model.NotificationListener.start(NotificationListener.java:32)\n\tat io.appium.uiautomator2.model.Session.(Session.java:23)\n\tat io.appium.uiautomator2.model.AppiumUiAutomatorDriver.initializeSession(AppiumUiAutomatorDriver.java:19)\n\tat io.appium.uiautomator2.handler.NewSession.safeHandle(NewSession.java:31)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:54)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:201)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:192)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)\n\tat io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)\n\tat io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)\n\tat io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)\n\tat io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:514)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468)\n\tat io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)\n\tat io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)\n\tat io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)\n\tat java.lang.Thread.run(Thread.java:818)\n"}} ProxyRequestError: Could not proxy command to remote server. Original error: 500 - {"status":13,"value":"java.lang.IllegalThreadStateException: Thread already started\n\tat java.lang.Thread.checkNotStarted(Thread.java:849)\n\tat java.lang.Thread.start(Thread.java:1059)\n\tat io.appium.uiautomator2.model.NotificationListener.start(NotificationListener.java:32)\n\tat io.appium.uiautomator2.model.Session.(Session.java:23)\n\tat io.appium.uiautomator2.model.AppiumUiAutomatorDriver.initializeSession(AppiumUiAutomatorDriver.java:19)\n\tat io.appium.uiautomator2.handler.NewSession.safeHandle(NewSession.java:31)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:54)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:201)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:192)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)\n\tat io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)\n\tat io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)\n\tat io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)\n\tat io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:514)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468)\n\tat io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)\n\tat io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)\n\tat io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)\n\tat java.lang.Thread.run(Thread.java:818)\n"}
at JWProxy.proxy$ (../../../lib/jsonwp-proxy/proxy.js:126:13)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js๐Ÿ’ฏ21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)

Environment

  • Appium version (or git revision) that exhibits the issue:1.6.3
  • Desktop OS/version used to run Appium:10.11.6
  • Node.js version (unless using Appium.app|exe):v7.2.1
  • Mobile platform/version under test:Android
  • Real device or emulator/simulator:Real device

Details

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: java.lang.IllegalThreadStateException: Thread already started
at java.lang.Thread.checkNotStarted(Thread.java:849)
at java.lang.Thread.start(Thread.java:1059)
at io.appium.uiautomator2.model.NotificationListener.start(NotificationListener.java:32)
at io.appium.uiautomator2.model.Session.(Session.java:23)
at io.appium.uiautomator2.model.AppiumUiAutomatorDriver.initializeSession(AppiumUiAutomatorDriver.java:19)
at io.appium.uiautomator2.handler.NewSession.safeHandle(NewSession.java:31)
at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:54)
at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:201)
at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:192)
at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:514)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:818)

@triager triager added the NeedsTriage label Dec 13, 2016
@sravanmedarapu
Member

@srkannan Can you please share appium server logs in a separate gist.

@sravanmedarapu
Member
sravanmedarapu commented Dec 15, 2016 edited

Quick investigation:

Typically uiautomator2-driver tries to kill the existing io.appium.uiautomator2.server process if any.

killProcessesByName relaying on PID to kill based on PID(adb shell kill PID) is not reliable always(especially on real devices). will return /system/bin/sh: kill: 29333: Operation not permitted.

As an alternative, should try to kill process with process name it self adb shell am force-stop io.appium.uiautomator2.server

@sravanmedarapu sravanmedarapu added the Bug label Dec 15, 2016
@sravanmedarapu sravanmedarapu self-assigned this Dec 19, 2016
@jlipps jlipps added this to the Gort [Sprint 4] milestone Dec 19, 2016
@sravanmedarapu sravanmedarapu referenced this issue in appium/appium-uiautomator2-driver Dec 28, 2016
Merged

Refactor #57

@sravanmedarapu
Member

Should work with appium-uiautomator2-driver v0.2.6

@priyankshah217

@sravanmedarapu , this issue is still alive. We tried with appium-1.6.4 Beta.Below are appium dependencies which appium-1.6.4 is using in my device
npm list -g | grep appium
โ”œโ”€โ”ฌ appium@1.6.4-beta
โ”‚ โ”œโ”€โ”ฌ appium-android-driver@1.11.3
โ”‚ โ”‚ โ”œโ”€โ”ฌ appium-adb@2.11.1
โ”‚ โ”‚ โ”œโ”€โ”ฌ appium-android-bootstrap@2.7.9
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ appium-uiautomator@1.1.0
โ”‚ โ”‚ โ”œโ”€โ”€ appium-android-ime@2.0.0
โ”‚ โ”‚ โ”œโ”€โ”ฌ appium-chromedriver@2.10.0
โ”‚ โ”‚ โ”œโ”€โ”€ appium-unlock@0.1.1
โ”‚ โ”‚ โ”œโ”€โ”€ io.appium.settings@2.1.0
โ”‚ โ”œโ”€โ”ฌ appium-base-driver@2.2.0
โ”‚ โ”œโ”€โ”ฌ appium-fake-driver@0.1.10
โ”‚ โ”œโ”€โ”ฌ appium-ios-driver@1.16.0
โ”‚ โ”‚ โ”œโ”€โ”ฌ appium-instruments@3.9.1
โ”‚ โ”‚ โ”œโ”€โ”ฌ appium-ios-simulator@1.17.1
โ”‚ โ”‚ โ”œโ”€โ”ฌ appium-remote-debugger@3.2.3
โ”‚ โ”‚ โ”œโ”€โ”ฌ appium-uiauto@2.3.3
โ”‚ โ”‚ โ”œโ”€โ”ฌ appium-xcode@3.1.2
โ”‚ โ”œโ”€โ”ฌ appium-logger@2.1.0
โ”‚ โ”œโ”€โ”ฌ appium-selendroid-driver@1.5.1
โ”‚ โ”œโ”€โ”ฌ appium-support@2.4.0
โ”‚ โ”œโ”€โ”ฌ appium-uiautomator2-driver@0.2.9
โ”‚ โ”‚ โ”œโ”€โ”€ appium-uiautomator2-server@0.1.0
โ”‚ โ”œโ”€โ”ฌ appium-windows-driver@0.4.0
โ”‚ โ”œโ”€โ”ฌ appium-xcuitest-driver@2.8.0
โ”‚ โ”œโ”€โ”ฌ appium-youiengine-driver@1.0.7
โ”‚ โ”‚ โ””โ”€โ”ฌ appium-android-driver@1.10.31
โ”œโ”€โ”ฌ appium-doctor@1.4.1
โ”‚ โ”œโ”€โ”ฌ appium-logger@2.1.0
โ”‚ โ”œโ”€โ”ฌ appium-support@2.4.0
โ”‚ โ”‚ โ”œโ”€โ”ฌ appium-xcode@3.1.2

Below is my appium log file.
https://gist.github.com/priyankshah217/598bd4fc0d6c61bc2122608cc54f24bf

The workaround which i was doing is uninstalling
io.appium.uiautomator2.server, io.appium.uiautomator2.server.test before starting appium server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment