question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UIAutomator2 crashes sometimes, causing "socket hang up"

See original GitHub issue

The problem

We are running an inhouse device farm, and encounter “socket hang up” errors from time to time.

Everyday we run about 800 test cases spreadly on 10 devices. Sometimes we got only some cases failed with this error, sometimes we failed ~20%, unpredictably.

Some devices are tough, only get this error once or twice. Some others are more fragile and get this error every now and then.

We tried to dive deeply into Appium’log and found this:

[HTTP] --> POST /wd/hub/session/f1daf4c7-4ef4-45df-ab0d-ebe6722e1f80/element
[HTTP] {"using":"id","value":"notification_container"}
[W3C (f1daf4c7)] Calling AppiumDriver.findElement() with args: ["id","notification_container","f1daf4c7-4ef4-45df-ab0d-ebe6722e1f80"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 0 ms for condition
[WD Proxy] Matched '/element' to command name 'findElement'
[WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8201/wd/hub/session/953fff26-affe-4ffa-9284-11ef8124c9f5/element] with body: {"strategy":"id","selector":"notification_container","context":"","multiple":false}
[Instrumentation] INSTRUMENTATION_RESULT: shortMsg=Process crashed.
[Instrumentation] INSTRUMENTATION_CODE: 0
[WD Proxy] socket hang up
[W3C (f1daf4c7)] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up
[W3C (f1daf4c7)]     at JWProxy.command (/home/linuxbrew/.linuxbrew/lib/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:280:13)
[W3C (f1daf4c7)]     at runMicrotasks (<anonymous>)
[W3C (f1daf4c7)]     at processTicksAndRejections (internal/process/task_queues.js:97:5)
[W3C (f1daf4c7)]     at AndroidUiautomator2Driver.helpers.doFindElementOrEls (/home/linuxbrew/.linuxbrew/lib/node_modules/appium/node_modules/appium-uiautomator2-driver/lib/commands/find.js:27:12)
[W3C (f1daf4c7)]     at doFind (/home/linuxbrew/.linuxbrew/lib/node_modules/appium/node_modules/appium-android-driver/lib/commands/find.js:36:17)
[W3C (f1daf4c7)]     at wrappedCondFn (/home/linuxbrew/.linuxbrew/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/timeout.js:151:12)
[W3C (f1daf4c7)]     at spin (/home/linuxbrew/.linuxbrew/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:113:20)
[W3C (f1daf4c7)]     at waitForCondition (/home/linuxbrew/.linuxbrew/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:129:10)
[W3C (f1daf4c7)]     at AndroidUiautomator2Driver.implicitWaitForCondition (/home/linuxbrew/.linuxbrew/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/timeout.js:153:10)
[W3C (f1daf4c7)]     at AndroidUiautomator2Driver.findElOrEls (/home/linuxbrew/.linuxbrew/lib/node_modules/appium/node_modules/appium-android-driver/lib/commands/find.js:60:5)
[W3C (f1daf4c7)]     at AndroidUiautomator2Driver.findElOrElsWithProcessing (/home/linuxbrew/.linuxbrew/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/find.js:33:12)
[W3C (f1daf4c7)]     at AndroidUiautomator2Driver.findElement (/home/linuxbrew/.linuxbrew/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/find.js:53:10)
[HTTP] <-- POST /wd/hub/session/f1daf4c7-4ef4-45df-ab0d-ebe6722e1f80/element 500 162 ms - 2041

This seems to be similar to issue https://github.com/appium/appium/issues/10749, and seems to be fixed in https://github.com/appium/appium-uiautomator2-driver/blob/80216fce6c9850ef14ee27284de4ab5cb6094ac6/lib/uiautomator2.js#L321.

But it still happens.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.18.3
  • Desktop OS/version used to run Appium: Ubuntu 18.04/20.04
  • Node.js version (unless using Appium.app|exe): 15.2.1
  • Npm or Yarn package manager: Npm
  • Mobile platform/version under test: Android 9/10
  • Real device or emulator/simulator: Read devices
  • Appium CLI or Appium.app|exe: Appium CLI

Details

If necessary, describe the problem you have been experiencing in more detail.

Link to Appium logs

https://gist.github.com/ltpquang/ce8689e433529aea585c602682deba14

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
mykola-mokhnachcommented, Nov 18, 2020

there might be multiple reasons for the instrumentation crash. Consider checking the logcat output to find possible traces there.

0reactions
ltpquangcommented, Nov 23, 2020

After opening this issue, I tried solution suggested by @dineshchakravarthy5 in https://github.com/appium/appium/issues/10749: explicitly wait for 10 seconds before creating a new session. Moreover, I also tried to start a new Appium server instance everytime the pipelines start to run, instead of having one instance running 24/7. Since then, nearly 100 test runs with ~5000 sessions created with only a few “socket hang up” occurrences. Maybe you folks can tried and comment back so the latter can get some hints to resolve this mystery.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UIAutomator2 crashes sometimes, causing "socket hang up"
The problem. We are running an inhouse device farm, and encounter "socket hang up" errors from time to time.
Read more >
[Bug]: io.appium.uiautomator2.server crashing with message ...
Details. I am using an Appium single server instance to connect multiple devices with their sessions to run tests on all connected devices....
Read more >
Error: socket hang up when running Android on Mac OS
I am running an Android test on Mac OS using Appium Application and after a certain time all the test are crashing.
Read more >
Socket Hang up issue - appium android - Stack Overflow
Chrome is crashing while image upload using selenium, How to fix it? 0 · Getting error HTTP Status: '404' -> incorrect JSON status...
Read more >
NodeJS - What does socket hang up actually mean - Edureka
When you send a request to a distant server as a client and don't get a response in a timely manner. This error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found