[Appium 1.22.1] - Android bootstrap socket crashed: Error: connect ECONNREFUSED 127.0.0.1:4724
See original GitHub issueThe problem
While running Appium inside a Docker container to run tests on Android devices using UiAutomator1, Appium seems to fail to connect the bootstrap port. I think maybe it’s using the wrong host address?
Environment
- Appium version (or git revision) that exhibits the issue: 1.22.1
- Last Appium version that did not exhibit the issue (if applicable): N/A (Didn’t try with other versions)
- Desktop OS/version used to run Appium: Ubuntu 18.04.6 (alpine:edge in Docker)
- Node.js version (unless using Appium.app|exe): v17.1.0
- Npm or Yarn package manager: npm 8.1.3
- Mobile platform/version under test: Android (SDK level 22)
- Real device or emulator/simulator: Real device (FireTV)
- Appium CLI or Appium.app|exe: Appium CLI
Details
I’ve started appium in the container with these args and it seems to fail at the same section in the logs for all of them:
In Docker container:
appium --address 127.0.0.1 --allow-insecure=adb_shell
appium --address 127.0.0.1 --callback-address host.docker.internal --allow-insecure=adb_shell
appium --address 0.0.0.0 --allow-insecure=adb_shell
I have ADB running on the host with:
adb -a nodaemon server
Section from Appium logs where it fails (full logs linked below):
[AndroidDriver] No app sent in, not parsing package/activity
[debug] [AndroidDriver] No app capability. Assuming it is already on the device
[debug] [AndroidBootstrap] Watching for bootstrap disconnect
[debug] [ADB] Forwarding system: 4724 to device: 4724
[debug] [ADB] Running '/opt/android-sdk/platform-tools/adb -H host.docker.internal -P 5037 -s G010L80779330494 forward tcp:4724 tcp:4724'
[debug] [UiAutomator] Starting UiAutomator
[debug] [UiAutomator] Moving to state 'starting'
[debug] [UiAutomator] Parsing uiautomator jar
[debug] [UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[debug] [ADB] Running '/opt/android-sdk/platform-tools/adb -H host.docker.internal -P 5037 -s G010L80779330494 shell mkdir -p /data/local'
[debug] [ADB] Running '/opt/android-sdk/platform-tools/adb -H host.docker.internal -P 5037 -s G010L80779330494 push /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/'
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting IDs of all 'uiautomator' processes
[debug] [ADB] Using ps-based PID detection
[debug] [ADB] Running '/opt/android-sdk/platform-tools/adb -H host.docker.internal -P 5037 -s G010L80779330494 shell ps'
[ADB] No 'uiautomator' process has been found
[debug] [UiAutomator] Starting UIAutomator
[debug] [ADB] Creating ADB subprocess with args: ["-H","host.docker.internal","-P",5037,"-s","G010L80779330494","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.amazon.tv.launcher","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[debug] [UiAutomator] Moving to state 'online'
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
uncaughtException: Android bootstrap socket crashed: Error: connect ECONNREFUSED 127.0.0.1:4724
Error: Android bootstrap socket crashed: Error: connect ECONNREFUSED 127.0.0.1:4724
at Socket.<anonymous> (/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/lib/bootstrap.js:97:21)
at Socket.emit (node:events:390:28)
at emitErrorNT (node:internal/streams/destroy:164:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Output of sudo netstat -lptn | grep 4724
after the error occurs:
tcp6 0 0 :::4724 :::* LISTEN 3530/adb
I tried to debug further by running the following commands manually:
/opt/android-sdk/platform-tools/adb -H host.docker.internal -P 5037 -s G010L80779330494 forward tcp:4724 tcp:4724
/opt/android-sdk/platform-tools/adb -H host.docker.internal -P 5037 -s G010L80779330494 shell mkdir -p /data/local
/opt/android-sdk/platform-tools/adb -H host.docker.internal -P 5037 -s G010L80779330494 push /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/
/opt/android-sdk/platform-tools/adb -H host.docker.internal -P 5037 -s G010L80779330494 shell ps
/opt/android-sdk/platform-tools/adb -H host.docker.internal -P 5037 -s G010L80779330494 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.amazon.tv.launcher -e disableAndroidWatchers false -e acceptSslCerts false &
And the output of that was:
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=
io.appium.android.bootstrap.Bootstrap:
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: test=testRunServer
INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS_CODE: 1
[APPIUM-UIAUTO] [debug] Socket opened on port 4724[/APPIUM-UIAUTO]
[APPIUM-UIAUTO] [debug] Appium Socket Server Ready[/APPIUM-UIAUTO]
[APPIUM-UIAUTO] [debug] Loading json...[/APPIUM-UIAUTO]
[APPIUM-UIAUTO] [debug] Registered crash watchers.[/APPIUM-UIAUTO]
I also tried wget 127.0.0.1:4724
from within the Docker container:
Connecting to 127.0.0.1:4724 (127.0.0.1:4724)
wget: can't connect to remote host (127.0.0.1): Connection refused
However, if I try wget host.docker.internal:4724
, it seems to work?
Connecting to host.docker.internal:4724 (240.10.0.1:4724)
[APPIUM-UIAUTO] [debug] Client connected[/APPIUM-UIAUTO]
[APPIUM-UIAUTO] [debug] Got data from client: GET / HTTP/1.1
Host: host.docker.internal:4724
User-Agent: Wget
Connection: close
[/APPIUM-UIAUTO]
^C (pressed Ctrl+C here)
/ # [APPIUM-UIAUTO] [debug] Got data from client: [/APPIUM-UIAUTO]
[APPIUM-UIAUTO] [debug] Got data from client: [/APPIUM-UIAUTO]
[APPIUM-UIAUTO] [error] Error processing data to/from socket (java.net.SocketException: sendto failed: EPIPE (Broken pipe))[/APPIUM-UIAUTO]
The command used to start the Docker container:
docker run -d --rm --init --add-host host.docker.internal:host-gateway --env ANDROID_SERIAL=G010L80779330494 --env SYSTEM_PORT=8200 --name=G010L80779330494 --mount type=bind,source=$PWD/G010L80779330494,target=/execution_directory -it automation-container:1.0
Link to Appium logs
Thank you so much. Any help with this would be appreciated.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top GitHub Comments
No changes have been done to this driver for quite a long time. It is considered obsolete and the Appium team does not maintain it. Consider switching to UiAutomator2/Espresso instead.
Unfortunately I’m not at liberty to change the driver since I don’t own the tests. However, I managed to find a way around the issue. Listing the solution here in case someone else also runs into the same issue.
Resolution:
iptables
available in the container--privileged --cap-add=NET_ADMIN --add-host host.docker.internal:host-gateway
appium --address 0.0.0.0 --suppress-adb-kill-server --allow-insecure=adb_shell