DeviceFarmer / stf

Control and manage Android devices from your browser.
https://devicefarmer.github.io
Other
3.51k stars 496 forks source link

stf-app unable to connect to rethinkdb:28015 #716

Closed hex354 closed 1 year ago

hex354 commented 1 year ago

Super hi for all!

Please help solved this puzzle I have 2 machince with static ip - Windows 11 192.168.0.249 (rethinkdb) and Ubuntu server 22.04.3 192.168.0.129 (stf) Then i run stf docker-compose.yaml stf-app container unable to connect to rethinkdb:28015

Let's look at what we have:

  1. Running rethinkdb:2.4.2 on Windows 11 via docker-compose.yaml like this
    
    version: '3.8'

services: rethinkdb: image: rethinkdb:2.4.2 container_name: rethinkdb restart: always ports:

volumes: rethinkdb_data:

rethinkdb accessable http://192.168.0.249:8080/

2. Running part of stf on Ubuntu server 22.04.3 via **docker-compose.yaml** like this:
(I’m launching partly because of testing and going through [DEPLOYMENT.md](https://github.com/DeviceFarmer/stf/blob/master/doc/DEPLOYMENT.md) step by step)

version: '3.8' services:

adbd: container_name: adbd image: 'devicefarmer/adb:latest' restart: unless-stopped ports:

My docker compose up output looks like this

[+] Running 3/3
 ✔ Container rethinkdb-proxy-28015  Created                                                                                                                                           0.0s
 ✔ Container adbd                   Created                                                                                                                                           0.0s
 ✔ Container stf-app                Created                                                                                                                                           0.1s
Attaching to adbd, rethinkdb-proxy-28015, stf-app
adbd                   | 10-13 15:13:59.127     7     7 I adb     : auth.cpp:416 adb_auth_init...
adbd                   | 10-13 15:13:59.127     7     7 I adb     : auth.cpp:152 loaded new key from '/root/.android/adbkey' with fingerprint 9BB6C5623F63CB10053006DE7335A39BE64999A41891CDE4A8B03F39BD3F9135
adbd                   | 10-13 15:13:59.127     7     7 I adb     : auth.cpp:391 adb_auth_inotify_init...
adbd                   | 10-13 15:13:59.276     7    14 I adb     : transport.cpp:307 4427f628: write thread spawning
adbd                   | 10-13 15:13:59.276     7    13 I adb     : transport.cpp:335 4427f628: read thread spawning
adbd                   | 10-13 15:13:59.286     7     7 I adb     : transport.cpp:1727 fetching keys for transport 4427f628
adbd                   | 10-13 15:13:59.286     7     7 I adb     : auth.cpp:468 Calling send_auth_response
adbd                   | 10-13 15:13:59.299     7     7 I adb     : adb.cpp:179 4427f628: offline
stf-app                | 2023-10-13T15:13:59.822Z INF/app 1 [*] Using pre-built resources
stf-app                | 2023-10-13T15:13:59.830Z INF/app 1 [*] Listening on port 3000
stf-app                | 2023-10-13T15:13:59.831Z INF/db 1 [*] Connecting to 127.0.0.1:28015
stf-app                | 2023-10-13T15:13:59.836Z INF/db 1 [*] Unable to connect to 127.0.0.1:28015
stf-app                | 2023-10-13T15:13:59.836Z FTL/db 1 [*] No hosts left to try
stf-app                | 2023-10-13T15:13:59.837Z FTL/util:lifecycle 1 [*] Shutting down due to fatal error
stf-app exited with code 0

I dont understand - why stf-app cant access to rethinkdb via rethinkdb-proxy-28015 Maybe something wrong with rethinkdb-proxy-28015 container?

If netcating or telneting windows port 28015 from ubuntu - everything its allright

root@stf:/home/stf/stf-separate-service# nc -zv 192.168.0.249 28015
Connection to 192.168.0.249 28015 port [tcp/*] succeeded!
root@stf:/home/stf/stf-separate-service# telnet 192.168.0.249 28015
Trying 192.168.0.249...
Connected to 192.168.0.249.
Escape character is '^]'.
^CConnection closed by foreign host.

What did I miss?

denis99999 commented 1 year ago

@ttork354 , Your configuration seems good, I don't know what is wrong at first glance, perhaps it is due to your Docker version at Ubuntu server side, I know links behave differently with the introduction of the Docker networks feature (cf. Docker Legacy container links), so I recommend you to switch to another solution if you are blocked, for example you could do these changes in your docker-compose file:

So, your docker-compose file should be something like that:

version: '3.8'
services:

  adbd:
    container_name: adbd
    image: 'devicefarmer/adb:latest'
    restart: unless-stopped
    ports:
      - "5037:5037"
    volumes:
      - '/dev/bus/usb:/dev/bus/usb'
    privileged: true

  stf-app:
    container_name: stf-app
    image: 'devicefarmer/stf:latest'
    restart: unless-stopped
    ports:
      - '3100:3000'
    environment:
      - SECRET=secret
      - RETHINKDB_PORT_28015_TCP=tcp://192.168.0.249:28015
    command: 'stf app --port 3000 --auth-url http://192.168.0.129/auth/mock --websocket-url http://192.168.0.129/'

I think it should works!

hex354 commented 1 year ago

@denis99999 well... try this and its not working for me...

output looks similar, but hints at network unavailability

[+] Running 2/0
 ✔ Container stf-app  Created                                                                                                                                                                                                                          0.0s
 ✔ Container adbd     Created                                                                                                                                                                                                                          0.0s
Attaching to adbd, stf-app
adbd     | 10-18 09:06:23.163     7     7 I adb     : auth.cpp:416 adb_auth_init...
adbd     | 10-18 09:06:23.163     7     7 I adb     : auth.cpp:152 loaded new key from '/root/.android/adbkey' with fingerprint 9BB6C5623F63CB10053006DE7335A39BE64999A41891CDE4A8B03F39BD3F9135
adbd     | 10-18 09:06:23.163     7     7 I adb     : auth.cpp:391 adb_auth_inotify_init...
adbd     | 10-18 09:06:23.537     7    13 I adb     : transport.cpp:335 4427f628: read thread spawning
adbd     | 10-18 09:06:23.537     7    14 I adb     : transport.cpp:307 4427f628: write thread spawning
adbd     | 10-18 09:06:23.556     7     7 I adb     : transport.cpp:1727 fetching keys for transport 4427f628
adbd     | 10-18 09:06:23.556     7     7 I adb     : auth.cpp:468 Calling send_auth_response
adbd     | 10-18 09:06:23.565     7     7 I adb     : adb.cpp:179 4427f628: offline
stf-app  | 2023-10-18T09:06:23.579Z INF/app 1 [*] Using pre-built resources
stf-app  | 2023-10-18T09:06:23.591Z INF/app 1 [*] Listening on port 3000
stf-app  | 2023-10-18T09:06:23.592Z INF/db 1 [*] Connecting to 192.168.0.249:28015
stf-app  | 2023-10-18T09:06:23.679Z INF/db 1 [*] Unable to connect to 192.168.0.249:28015
stf-app  | 2023-10-18T09:06:23.680Z FTL/db 1 [*] No hosts left to try
stf-app  | 2023-10-18T09:06:23.680Z FTL/util:lifecycle 1 [*] Shutting down due to fatal error
stf-app exited with code 0

in an attempt to find out the reason and eliminate network problems, I simply launched separate containers with a minimum of parameters on one Ubuntu server localy - rethinkdb and stf-app

rethinkdb running comand on Ubuntu 192.168.0.129:

 docker run --rm \
  --name rethinkdb \
  -v /srv/rethinkdb:/home/stf/data \
  -e "AUTHKEY=stf" \
  --net host \
  rethinkdb:2.4.2 \
  rethinkdb --bind all \
    --cache-size 2048 \
    --no-update-check \
    --initial-password stf

output from running rethinkdb below - how can we see rethinkdb bind to 192.168.0.129

Recursively removing directory /data/rethinkdb_data/tmp
Initializing directory /data/rethinkdb_data
Running rethinkdb 2.4.2~0bullseye (GCC 10.2.1)...
Running on Linux 5.15.0-86-generic x86_64
Loading data from directory /data/rethinkdb_data
Listening for intracluster connections on port 29015
Listening for client driver connections on port 28015
Listening for administrative HTTP connections on port 8080
Listening on cluster addresses: 127.0.0.1, 172.17.0.1, 172.18.0.1, 172.19.0.1, 172.20.0.1, 192.168.0.129, ::1, fe80::42:57ff:fe36:96b%7, fe80::42:7fff:feda:3b8b%5, fe80::42:f5ff:fe0e:9929%4, fe80::b222:7aff:fef8:b6ed%2
Listening on driver addresses: 127.0.0.1, 172.17.0.1, 172.18.0.1, 172.19.0.1, 172.20.0.1, 192.168.0.129, ::1, fe80::42:57ff:fe36:96b%7, fe80::42:7fff:feda:3b8b%5, fe80::42:f5ff:fe0e:9929%4, fe80::b222:7aff:fef8:b6ed%2
Listening on http addresses: 127.0.0.1, 172.17.0.1, 172.18.0.1, 172.19.0.1, 172.20.0.1, 192.168.0.129, ::1, fe80::42:57ff:fe36:96b%7, fe80::42:7fff:feda:3b8b%5, fe80::42:f5ff:fe0e:9929%4, fe80::b222:7aff:fef8:b6ed%2
Server ready, "stf_vsz" f5074fad-66f6-4cae-849c-177c004bf9dd

stf-app running command on Ubuntu 192.168.0.129:

docker run --rm \
  --name stf-app \
  -e "SECRET=secret" \
  -e "AUTHKEY=stf" \
  -e "RETHINKDB_PORT_28015_TCP=tcp://192.168.0.129:28015" \
  --net host \
  devicefarmer/stf:latest \
  stf app --port 3000 --auth-url http://192.168.0.129/auth/mock --websocket-url http://192.168.0.129/ 

and output stay the same:

2023-10-18T09:39:27.641Z INF/app 1 [*] Using pre-built resources
2023-10-18T09:39:27.648Z INF/app 1 [*] Listening on port 3000
2023-10-18T09:39:27.654Z INF/db 1 [*] Connecting to 192.168.0.129:28015
2023-10-18T09:39:27.740Z INF/db 1 [*] Unable to connect to 192.168.0.129:28015
2023-10-18T09:39:27.740Z FTL/db 1 [*] No hosts left to try
2023-10-18T09:39:27.740Z FTL/util:lifecycle 1 [*] Shutting down due to fatal error

Maybe there are other ways to debug this problem? Now looks like an internal container problem Or maybe I just missed some basics

denis99999 commented 1 year ago

@ttork354 this looks like a firewall issue on your Ubuntu server, have you disabled UFW and checked your iptables? Did you install Docker following the official instructions? Also, I saw on the internet that Ubuntu 22.04 could cause problems regarding the network accessibility of Docker containers, have you done any research in this direction? I don't think the problem comes from STF, to be convinced, just test access to rethinkdb from a standard container in interactive mode (e.g. telnet 192.168.0.129 28015), tell me what that gives? Also, try to launch stf migrate which initialize STF database!

hex354 commented 1 year ago

My Ubuntu installing with default settings, ufw inactive and iptables should be accept all Command ufw status verbose tell me that - thats all... Status: inactive

Command iptables -S tell me

-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-N DOCKER
-N DOCKER-ISOLATION-STAGE-1
-N DOCKER-ISOLATION-STAGE-2
-N DOCKER-USER

Command from Windows 192.168.0.249 telnet 192.168.0.129 28015 output

Trying 192.168.0.129...
Connected to 192.168.0.129.
Escape character is '^]'. # From this line i press Ctrl + C for escape
Connection closed by foreign host.

Command from Ubuntu 192.168.0.129 telnet 192.168.0.129 28015 output the same

Trying 192.168.0.129...
Connected to 192.168.0.129.
Escape character is '^]'. # From this line i press Ctrl + C for escape
Connection closed by foreign host.

My docker installation method is https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository

denis99999 commented 1 year ago

@ttork354 did you run the telnet command from a Docker container as I precised in my last message ?

hex354 commented 1 year ago

rethinkdb still running in Ubutnu 192.168.0.129 and accessible http://192.168.0.129:8080/#dashboard

iam trying this container with telnet

docker pull realworld/telnet
docker run -it realworld/telnet

inside run command OPEN 192.168.0.129 28015 output

Trying 192.168.0.129...
Connected to 192.168.0.129.
Escape character is '^]'.
^CConnection closed by foreign host.

it looks like everything is ok with rethinkdb

denis99999 commented 1 year ago

@ttork354 while connecting to rethinkdb through the Ui, are you able to create a table in the test database without errors ? Is your Ubuntu OS is 64 bit one ? Did you run stf migrate?

denis99999 commented 1 year ago

@ttork354, I installed an Ubuntu 22.04 server with Docker and I have no error connecting STF service units (app or migrate) to the rethinkdb database, maybe you have a problem in your Docker installation because I see a difference between your iptables and mine, as follows:

# iptables -S
-P INPUT ACCEPT
-P FORWARD DROP
-P OUTPUT ACCEPT
-N DOCKER
-N DOCKER-ISOLATION-STAGE-1
-N DOCKER-ISOLATION-STAGE-2
-N DOCKER-USER
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-ISOLATION-STAGE-1
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -j RETURN
-A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -j RETURN
-A DOCKER-USER -j RETURN
hex354 commented 1 year ago

try clean install from scratch and its works fine i have no idea whats wrong...

many thanks for your interest @denis99999