remote-android / redroid-doc

redroid (Remote-Android) is a multi-arch, GPU enabled, Android in Cloud solution. Track issues / docs here
4.2k stars 299 forks source link

Unable to Connect Multiple Containers via ADB or scrppy on ubuntu 22 #677

Open mazaheriaan opened 5 months ago

mazaheriaan commented 5 months ago

I run redroid/redroid:12.0.0-latest . Although I have mapped different ports to the standard ADB port (5555) for each emulator, only the first container can connect via ADB. If the first container is stopped, then the next one can connect. This behavior suggests that ADB connections are limited to only one container at a time. I also tested with androidboot.redroid_gpu_mode=guest but this did not resolve the issue.

First container

docker run -itd --rm --privileged \
    --pull always \
    -v ~/data2:/data \
    -p 5555:5555 \
  redroid/redroid:12.0.0-latest

Second

docker run -itd --rm --privileged \
    --pull always \
    -v ~/data3:/data \
    -p 5556:5555 \
  redroid/redroid:12.0.0-latest

Attempt to connect to both containers via ADB:

adb connect localhost:5555
adb connect localhost:5556

Observe that only the first container is accessible.

dmesg log

dmesg.txt

Update

After updating and restarting the OS, the issue was fixed. I can't identify the cause of the problem.

zhouziyang commented 5 months ago

According your setup. should connect to the following ports.

adb connect localhost:5555
adb connect localhost:5556
mazaheriaan commented 5 months ago

According your setup. should connect to the following ports.

adb connect localhost:5555
adb connect localhost:5556

Sorry, I made a typo. I have corrected it. However, it still cannot connect.

zhouziyang commented 5 months ago

Can you paste the commands (with the outputs) you typed? And, please attach the two debug blobs (dmesg is not enough).

brunoaduarte commented 3 months ago

@zhouziyang How can I make all devices appear on adb devices automatically after adb startup ? adb connect to each port works, but only the first device emulator-5554 appears on the list of running devices before the manual connections.

ubuntu@ubuntu:~$ adb kill-server
ubuntu@ubuntu:~$ adb devices
List of devices attached
emulator-5554   device

ubuntu@ubuntu:~$ adb connect localhost:5555
connected to localhost:5555
ubuntu@ubuntu:~$ adb connect localhost:5556
connected to localhost:5556

ubuntu@ubuntu:~$ adb devices
List of devices attached
emulator-5554   device
localhost:5555  device
localhost:5556  device
zhouziyang commented 3 months ago

Try scripting?

emulator-5554 is shown due to :5555 port opened.

brunoaduarte commented 3 months ago

Try scripting?

emulator-5554 is shown due to :5555 port opened.

In fact, as per ADB documentation

How adb works
....
The server then sets up connections to all running devices.

It locates emulators by scanning odd-numbered ports in the range 5555 to 5585, 
which is the range used by the first 16 emulators.

Where the server finds an adb daemon (adbd), it sets up a connection to that port.

Each emulator uses a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections.
For example:

Emulator 1, console: 5554
Emulator 1, adb: 5555
Emulator 2, console: 5556
Emulator 2, adb: 5557
and so on.

As shown, the emulator connected to adb on port 5555 is the same as the emulator whose console listens on port 5554.

We should use only odd numbered ports for the host mapping. So instead of running the second emulator on port 5556 it should be bind to port 5557. Then adb devices works perfectly automatically scanning and connecting

docker run -itd --privileged --name redroid1 -v /home/ubuntu/redroid1:/data -p 5555:5555  redroid/redroid:12.0.0_64only-latest
docker run -itd --privileged --name redroid2 -v /home/ubuntu/redroid2:/data -p 5557:5555  redroid/redroid:12.0.0_64only-latest

adb devices
List of devices attached
emulator-5554   device
emulator-5556   device
brunoaduarte commented 3 months ago

BTW @zhouziyang i'm trying to run 6~10 instances at the same time but as soon as I launch the 5th instance my ssh connection freezes and I have to stop all the docker containers for it to work again. Is there a way to improve multi instance ? Memory is not the issue as there are 64GB RAM allocated to the Ubuntu host qemu VM (from the physical 128GB RAM of my Windows 11 PC) and the memory consumption with 4 instances running is still very low

image

brunoaduarte commented 3 months ago
[ 2033.246957] init: Sending signal 9 to service 'idmap2d' (pid 147) process group...
[ 2033.254764] init: Control message: Processed ctl.stop for 'idmap2d' from pid: 401 (system_server)
[ 2033.255158] init: Service 'idmap2d' (pid 147) received signal 9
[ 2045.146491] binder_linux: 54279: binder_alloc_buf size 1056768 failed, no address space
[ 2045.146499] binder_linux: allocated: 4784 (num: 12 largest: 1712), free: 1035600 (num: 5 largest: 1034600)
[ 2045.146501] binder_linux: cannot allocate buffer: no space left
[ 2045.146503] binder_linux: 54320:55615 transaction call to 54279:0 failed 1870985/29201/-28, size 1056768-0 line 3253
[ 2067.271576] clocksource: timekeeping watchdog on CPU14: hpet wd-wd read-back delay of 65700ns
[ 2067.271583] clocksource: wd-tsc-wd read-back delay of 107500ns, clock-skew test skipped!
[ 2082.065605] binder_linux: 53630:53492 cannot find target node
[ 2082.065612] binder_linux: 53492:53630 transaction async to 0:0 failed 2035303/29189/-22, size 116-0 line 3065
[ 2099.457923] binder_linux: 29790:29862 ioctl 400c620e 7980649a66b8 returned -22
[ 2111.498920] binder_linux: 33549:33913 ioctl 400c620e 7255f1d3e6b8 returned -22
[ 2116.485742] binder_linux: 33549:33913 ioctl 400c620e 7255f1d3e6b8 returned -22
[ 2119.771446] binder_linux: 33355:33830 ioctl 400c620e 7dde6c1bc6b8 returned -22
zhouziyang commented 3 months ago

BTW @zhouziyang i'm trying to run 6~10 instances at the same time but as soon as I launch the 5th instance my ssh connection freezes and I have to stop all the docker containers for it to work again. Is there a way to improve multi instance ? Memory is not the issue as there are 64GB RAM allocated to the Ubuntu host qemu VM (from the physical 128GB RAM of my Windows 11 PC) and the memory consumption with 4 instances running is still very low

image

Please file a new issue with debug logs (especially the dmesg) and reproduce steps. Please close this thread if your original issue resolved, thanks!