Unknown server issue socket hang up

I got this issue with something like this:

[debug] e[35m[W3C (58f83265)]e[39m 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
[debug] e[35m[W3C (58f83265)]e[39m at UIA2Proxy.command (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:274:13)
[debug] e[35m[W3C (58f83265)]e[39m at runMicrotasks ()
[debug] e[35m[W3C (58f83265)]e[39m at processTicksAndRejections (internal/process/task_queues.js:95:5)
[debug] e[35m[W3C (58f83265)]e[39m at AndroidUiautomator2Driver.helpers.doFindElementOrEls (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-driver\lib\commands\find.js:30:12)
[debug] e[35m[W3C (58f83265)]e[39m at doFind (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:36:17)
[debug] e[35m[W3C (58f83265)]e[39m at wrappedCondFn (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\commands\timeout.js:151:12)
[debug] e[35m[W3C (58f83265)]e[39m at spin (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\asyncbox\lib\asyncbox.js:138:20)
[debug] e[35m[W3C (58f83265)]e[39m at waitForCondition (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\asyncbox\lib\asyncbox.js:154:10)
[debug] e[35m[W3C (58f83265)]e[39m at AndroidUiautomator2Driver.implicitWaitForCondition (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\commands\timeout.js:153:10)
[debug] e[35m[W3C (58f83265)]e[39m at AndroidUiautomator2Driver.findElOrEls (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:60:5)
[debug] e[35m[W3C (58f83265)]e[39m at AndroidUiautomator2Driver.findElOrElsWithProcessing (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\commands\find.js:33:12)
[debug] e[35m[W3C (58f83265)]e[39m at AndroidUiautomator2Driver.findElementsFromElement (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\commands\find.js:71:10)

Somehow it is related to node js but I am not sure how do I start to resolve this issue, anyone knows about this issue?

give a bit more info when it happens and how often

Hi sure, I have a test suite (TestNG) that has few Appium test cases in it and then execute with gradlew command, it is running fine in my local machine but it’s not when I use some sort of Jenkins to trigger some batch file to execute gradlew command so that it will starts run the Appium test cases. It is running fine until one specific test case (not the test case issue), around 17 minutes and then the unknown server issue like the log above keep showing up and thus failed the rest of the test cases. It happens every single time I trigger Jenkins job and execute the gradlew command to run the Appium test cases

I have tried various method and it’s not resolving this issue:

disable battery power optimization
disconnect adb after one test suite executed
change new connection cable for device
factory reset
uninstall appium apk
task kill node.exe
change new LAN cable
set Appium time idle timeout to 100

so TestNG.

  1. you should start appium servers in beforeSuite and stop servers afterSuite.
  2. you should open driver in beforeMethod and quit in afterMethod
  3. are you running tests in parallel or with one device?
  1. I already set start Appium server in BeforeSuite and then stop the server AfterSuite, it is AppiumDriverLocalService, is that right?
  2. You mean every time I create a driver from DriverManager I need to close it at afterMethod?
  3. So far I only run tests with one device, but in the future I want to make it so that it can support two radios interaction test
  1. any way you like. e.g. start in Java command executor.
  2. yes in most cases.

Hi, when you said that I need to close the driver in every method, the driver you referring to is the setCapability thing, right?

Right. In beforeMethod you start driver with some capabolities. And in afterMethod you quit driver.

Hi, it’s been a while, I already implemented as you suggest but the issue is still there, anything I can do to resolve it? I don’t understand why it only happen in my workstation machine that trigger job via Jenkins but not locally

Hi, I attached my Appium server log AppiumABAC_ServerLog.txt (222.7 KB) and you can see at the timestamp of 2021-11-25 07:46:21:926 it started to fail my Appium test cases in the exact 20 minutes from the start time, could you help to check on this, really appreciate it if you see my message.

last log in file is

2021-11-24 06:25:06:510 [HTTP] 

Oops, I am really sorry, this is the correct one Appium_ServerLog.txt (2.6 MB)

i see Appium is a bit old.

  1. try with new 1.22
  2. here i see we execute one test for more than 20 min. correct? so we see problem during long test only?
  3. do you execute tests in parallel or in one thread?
  1. Just installed and currently trying
  2. Correct, I only see this problem during long test (usually more than 20 minutes)
  3. I only execute tests in one thread

After I installed the latest Appium version which is 1.22.1, it popped out some new errors

17:30:35.830 [ForkJoinPool.commonPool-worker-1] INFO - Starting APPIUM Server for Device:
uncaughtException: EPERM: operation not permitted, stat ‘C:\Users\amb3942\Documents\testation\Appium_ServerLog.txt’
Error: EPERM: operation not permitted, stat ‘C:\Users\amb3942\Documents\testation\Appium_ServerLog.txt’
throw ex;
NodeError: write after end
at writeAfterEnd (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_writable.js:261:12)
at PassThrough.Writable.write (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_writable.js:305:21)
at File.log (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\winston\lib\winston\transports\file.js:185:34)
at File._write (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\winston-transport\index.js:103:17)
at doWrite (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\winston-transport\node_modules\readable-stream\lib_stream_writable.js:428:64)
at writeOrBuffer (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\winston-transport\node_modules\readable-stream\lib_stream_writable.js:417:5)
at File.Writable.write (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\winston-transport\node_modules\readable-stream\lib_stream_writable.js:334:11)
at DerivedLogger.ondata (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_readable.js:681:20)
at DerivedLogger.emit (events.js:326:22)
at addChunk (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_readable.js:298:12)
at readableAddChunk (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_readable.js:280:11)
at DerivedLogger.Readable.push (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_readable.js:241:10)
at DerivedLogger.Transform.push (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_transform.js:139:32)
at DerivedLogger._transform (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\winston\lib\winston\logger.js:305:12)
at DerivedLogger.Transform._read (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_transform.js:177:10)
at DerivedLogger.Transform._write (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_transform.js:164:83)
Emitted ‘error’ event on PassThrough instance at:
at errorOrDestroy (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib\internal\streams\destroy.js:98:101)
at writeAfterEnd (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_writable.js:263:3)
at PassThrough.Writable.write (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_writable.js:305:21)
[… lines matching original stack trace …]
at DerivedLogger.Transform._read (C:\Users\amb3942\AppData\Roaming\npm\node_modules\appium\node_modules\readable-stream\lib_stream_transform.js:177:10)

Anything I need to do to prevent these errors?

-> looks like https://github.com/appium/appium/issues/14770

Hi, I found out that the link to the GitHub issue is not helping me, what does it mean by using appropriate server arguments?

In the previous Appium version, this is not an issue at all.
Can you suggest a way to resolve this issue? Really much appreciate it.

I do not use Appium java builder. Try reopen issue or create new one.

I run appium as:

List list = new ArrayList<String>();
list.add("1800"); // 30 min
list.add("-g"); // here where logs to save
list.add("./target/" + deviceName + ".log");

ProcessBuilder pb = new ProcessBuilder(list);
Process appiumProcess = pb.start();
// and stop process after suite