On Android, Appium does not touch the UI itself. The UiAutomator2 driver installs a small server app on the device and sends every command to it over HTTP. When that server stops, your test sees one of two errors:

  • '<METHOD> <url>' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details
  • Could not proxy command to the remote server. Original error: socket hang up (or another connection error such as ECONNREFUSED)

This article explains how the driver runs that server, what each message tells you, and what usually stops it.

Short answer: both messages mean the server on the device is no longer answering. The first means the driver saw the server's process exit. The second means the HTTP connection to the server failed. The most common cause is that something else ended the server: your own code quitting the session, a new session on the same device, or the session timing out. The next most common is Android itself killing the process. Find the exit line in the Appium log, check logcat around that time, and make sure each device is used by only one session.

How the driver runs the server

When a session starts, the UiAutomator2 driver (version 9.0.1 at the time of writing) does this:

  1. It installs two packages if they are missing or outdated: io.appium.uiautomator2.server and io.appium.uiautomator2.server.test.
  2. It cleans up leftovers. It asks the server on the session's port for running sessions, deletes them, and force-stops both server packages.
  3. It starts the server with adb shell am instrument -w ... io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner. That adb shell command stays open for the whole session.
  4. It polls the server's /status endpoint until it answers, for up to appium:uiautomator2ServerLaunchTimeout (default 30000 ms).

The driver watches the adb shell am instrument process from step 3. When that process exits, the driver logs this line and marks the server as gone:

[Instrumentation] The process has exited with code <code>, signal <signal>

After that, every command fails at once with the "probably crashed" message. The driver does not even try to send it.

The process on the host exits when the instrumentation on the device ends. It also exits when the adb connection that carries it ends. So "probably crashed" does not always mean the server crashed. It means the driver lost the process it was watching.

The two messages

"cannot be proxied … instrumentation process is not running (probably crashed)"

The driver already saw the exit line above. Search the Appium server log for [Instrumentation]. Lines with this prefix are the output of the instrumentation command, and the last ones before the exit can name the reason. The exit happened before the failed command, sometimes long before. Look at what the test did, and what else happened on the device, at the time of the exit line, not at the time of the error.

The <METHOD> <url> part only tells you which command was the first to fail. For example 'GET /' or 'POST /element'. It does not tell you the cause.

"Could not proxy command to the remote server. Original error: socket hang up"

This comes from Appium's HTTP proxy. It means the request got no HTTP response at all: the connection was closed, refused or reset. The text after Original error: is the network error from Node.js. The driver's troubleshooting guide lists three causes for this: the session was already ended by your script, Android terminated the server, or the connection between the phone and the host is unstable.

You often see this message first and the "probably crashed" message on the next command. The first command was in flight when the server died. The driver noticed the exit before the second command.

During session start: "cannot be initialized"

If the server stops while the session is starting, the messages are different:

  • The instrumentation process cannot be initialized within <timeout>ms timeout. Make sure the application under test does not crash and investigate the logcat output. You could also try to increase the value of 'uiautomator2ServerLaunchTimeout' capability
  • The instrumentation process cannot be initialized. Make sure the application under test does not crash and investigate the logcat output.

Before giving up, the driver retries once. It logs The instrumentation process has been unexpectedly terminated. Retrying UiAutomator2 startup (#1 of 1), cleans up more strictly (this time it also kills processes named uiautomator on the device), and waits 3 seconds. If you see the retry line but the session then starts, the same thing will probably happen again under load.

Cause 1: something ended the server on purpose

This is the cause to rule out first, because it is not a bug in Appium or on the device.

Your code quit the session. The driver's troubleshooting guide says that a Delete Session request "terminates both the session and the UiAutomator2 server on the device. Any further commands sent to the same UiAutomator2 server would return a socket hangup error." Look for a driver.quit() in a teardown, a fixture or a retry wrapper that runs earlier than you expect. A common case: a shared driver used by several tests, where one test's teardown quits it.

A new session started on the same device. Step 2 above runs at the start of every session: the driver deletes the sessions it finds on its port and force-stops the server packages on the device. The force-stop does not depend on the port. So if a second session starts on a device while a first session is still running, the first session's server is stopped. The first session then fails with exactly these errors. The driver's parallel testing guide says: "a single device under test should only be used in one session at a time."

This happens when:

  • Two CI jobs or two Appium servers pick the same device or emulator.
  • A test runner runs tests in parallel against one device.
  • A retry starts a new session before the old one was quit.

For parallel runs, give each session its own device and its own ports. The guide lists appium:udid (real devices) or appium:avd (emulators), appium:systemPort, and appium:chromedriverPort and appium:mjpegServerPort when you use them:

{
  "platformName": "Android",
  "appium:automationName": "UiAutomator2",
  "appium:udid": "emulator-5556",
  "appium:systemPort": 8202
}

If you do not run sessions in parallel, the guide suggests the --session-override server flag, which deletes all existing sessions when a new one starts. That way an old session ends cleanly instead of failing half way.

The session timed out. appium:newCommandTimeout defaults to 60 seconds. If your test sends no command for longer than that (a long sleep, a breakpoint, a slow step outside Appium), Appium ends the session, and with it the server on the device. The driver's troubleshooting guide lists this timeout among the causes of the socket hangup error. Raise the value for those tests, or set it to 0 to turn the timeout off while debugging.

Cause 2: Android killed the server

If nothing in your code or on the CI side explains the exit, look at the device. The troubleshooting guide's advice is to fetch the logcat output and find io.appium.uiautomator2.server entries labeled error or exception. Save logcat right after the failure, before the device is reused or the emulator is closed:

adb -s <udid> logcat -d > logcat.txt
grep -n -i -E "io\.appium\.uiautomator2|FATAL EXCEPTION" logcat.txt

Look at the entries around the time of the [Instrumentation] exit line in the Appium log. In the guide's words, the server can crash because of "internal phone optimizations", a bug in the UI Automator framework, or a bug in the server itself.

Things to check on the device side:

  • Vendor power or app management. Some devices stop background processes on their own. If the problem happens only on one device model, check its battery and app management settings for the two server packages. The guide says some phone optimizations may need to be turned off.
  • Memory pressure on emulators. Under low memory, Android can kill processes. If failures cluster when many emulators run on one host, check host memory and the emulator's RAM size.
  • Old server packages. After a driver update, older server packages can stay cached on the device. The driver includes a script that removes its packages from all connected devices; the next session installs fresh ones:
appium driver run uiautomator2 reset
  • appium:skipServerInstallation. This capability skips installing the server and all related checks. The docs warn that "unexpected errors may occur if the UiAutomator2 server app is not compatible with the driver or the app under test". If you set it, turn it off and test again.

The driver's error message also says to make sure "the application under test does not crash". If logcat shows your own app crashing at the same moment, fix or isolate that first.

Cause 3: the adb connection dropped

The driver watches an adb shell process on the host. If the adb connection to the device ends, that process exits too, and the driver reports the instrumentation as stopped even if the server on the device is fine.

Signs of this case: the device disappears from adb devices for a moment, the Appium log shows other adb commands failing around the same time, or the failures follow a USB hub, cable or host rather than a test.

The guide's section on unstable connections names a defective phone, a damaged USB cable or an outdated Android SDK. For real devices, test with a direct, known good cable and port, and keep platform-tools current. On a shared host, check that no other job runs adb kill-server or restarts the adb server during your run, because that ends every connection on the host.

Timeouts that change the symptom

Two capabilities change how long the driver waits for the server. They do not keep the server alive:

  • appium:uiautomator2ServerLaunchTimeout (default 30000 ms): how long the driver waits for the server to start. Raise it for slow emulators that fail with the "within ms timeout" message.
  • appium:uiautomator2ServerReadTimeout (default 240000 ms): how long the driver waits for a response to one request.

If the server process exited, a longer timeout only makes the test fail later. Find out why it exited instead.

Checklist

  1. Search the Appium log for [Instrumentation] The process has exited. Note the time.
  2. Check what your test did at that time. Look for an early quit() and for steps longer than newCommandTimeout.
  3. Make sure no other session, job or Appium server used the same device at that time. Give each parallel session its own udid and systemPort.
  4. Save adb logcat -d right after the failure and look for io.appium.uiautomator2.server errors and app crashes.
  5. Check whether the device dropped from adb devices, and whether anything restarted the adb server.
  6. After a driver update, run appium driver run uiautomator2 reset. Do not use skipServerInstallation while debugging.
  7. Raise uiautomator2ServerLaunchTimeout only for slow startups, not for crashes.

Sources

Checked on 2026-11-08 against the source and documentation of Appium 3.9.0 and UiAutomator2 driver 9.0.1 (current master of the appium and appium-uiautomator2-driver repositories):