Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow connection time #54

Closed
KreativeKrise opened this issue Jul 5, 2022 · 25 comments
Closed

Slow connection time #54

KreativeKrise opened this issue Jul 5, 2022 · 25 comments
Labels
help wanted Extra attention is needed

Comments

@KreativeKrise
Copy link
Contributor

KreativeKrise commented Jul 5, 2022

If I want to connect to a remote system it takes 20-30 seconds. But mostly it timeouts after 30 seconds. Both systems are running Windows 10 with RustDesk 1.1.9.

RustDesk Server was installed via docker and docker-compose on a public available server.

I used this docker-compose config:

version: '3'

services:
  rustdesk-server:
    container_name: rustdesk-server
    network_mode: host
    image: rustdesk/rustdesk-server-s6:latest
    environment:
      - "RELAY=<PUBLIC_IP>:21117"
      - "ENCRYPTED_ONLY=1"
    volumes:
      - ./data:/data
    restart: unless-stopped

but I also tried:

version: '3'

services:
  rustdesk-server:
    container_name: rustdesk-server
    ports:
      - 21115:21115
      - 21116:21116
      - 21116:21116/udp
      - 21117:21117
      - 21118:21118
      - 21119:21119
    image: rustdesk/rustdesk-server-s6:latest
    environment:
      - "RELAY=<PUBLIC_IP>:21117"
      - "ENCRYPTED_ONLY=1"
    volumes:
      - ./data:/data
    restart: unless-stopped

Ports 21115-21119/tcp and 21116/udp for incoming connections are open.

Any idea what could cause this long time it needs to connect?

@rustdesk rustdesk added the help wanted Extra attention is needed label Jul 5, 2022
@paspo
Copy link
Contributor

paspo commented Jul 5, 2022

It usually takes a lot less than that.

Let's exclude a couple of things:

  • DNS: (because "it's always DNS") can you try to use the public IP address in both clients and in the RELAY=<PUBLIC_IP> configuration?
  • encryption key (you've specified RENCRYPTED_ONLY=1): can you confirm that you entered the same key on both clients? (you get the key from id_ed25519.pub)

Also, the container logs is really welcome...

@rustdesk
Copy link
Owner

rustdesk commented Jul 5, 2022

@KreativeKrise
Copy link
Contributor Author

KreativeKrise commented Jul 5, 2022

Here is the log:

root@server:~# docker logs -f rustdesk-server
/package/admin/s6-overlay/libexec/preinit: notice: /var/run is not a symlink to /run, fixing it
s6-rc: info: service hbbs: starting
s6-rc: info: service hbbr: starting
s6-rc: info: service s6rc-oneshot-runner: starting
[2022-07-05 15:04:29.915184 +00:00] INFO [src/relay_server.rs:60] #blacklist(blacklist.txt): 0
[2022-07-05 15:04:29.915194 +00:00] INFO [src/relay_server.rs:75] #blocklist(blocklist.txt): 0
[2022-07-05 15:04:29.915196 +00:00] INFO [src/relay_server.rs:81] Listening on tcp 0.0.0.0:21117
[2022-07-05 15:04:29.915199 +00:00] INFO [src/relay_server.rs:83] Listening on websocket 0.0.0.0:21119
[2022-07-05 15:04:29.915201 +00:00] INFO [src/relay_server.rs:85] Start
[2022-07-05 15:04:29.915220 +00:00] INFO [src/relay_server.rs:104] DOWNGRADE_THRESHOLD: 0.66
[2022-07-05 15:04:29.915689 +00:00] INFO [src/peer.rs:82] DB_URL=./db_v2.sqlite3
[2022-07-05 15:04:29.916184 +00:00] INFO [src/rendezvous_server.rs:94] serial=0
[2022-07-05 15:04:29.916191 +00:00] INFO [src/common.rs:41] rendezvous-servers=[]
[2022-07-05 15:04:29.916193 +00:00] INFO [src/rendezvous_server.rs:96] Listening on tcp/udp 0.0.0.0:21116
[2022-07-05 15:04:29.916194 +00:00] INFO [src/rendezvous_server.rs:97] Listening on tcp 0.0.0.0:21115, extra port for NAT test
[2022-07-05 15:04:29.916196 +00:00] INFO [src/rendezvous_server.rs:98] Listening on websocket 0.0.0.0:21118
[2022-07-05 15:04:29.916210 +00:00] INFO [libs/hbb_common/src/udp.rs:33] Receive buf size of udp 0.0.0.0:21116: Ok(212992)
[2022-07-05 15:04:29.916241 +00:00] INFO [src/common.rs:108] Private key comes from id_ed25519
[2022-07-05 15:04:29.916247 +00:00] INFO [src/rendezvous_server.rs:1126] Key: JPlhMhJPTr8CDl673Q1sssZoQQw0WMmGo3ImD1X6IGI=
[2022-07-05 15:04:29.916254 +00:00] INFO [src/common.rs:41] relay-servers=["<PUBLIC_IP>:21117"]
[2022-07-05 15:04:29.916296 +00:00] INFO [src/rendezvous_server.rs:135] ALWAYS_USE_RELAY=N
[2022-07-05 15:04:29.916307 +00:00] INFO [src/rendezvous_server.rs:155] Start
[2022-07-05 15:04:29.917274 +00:00] INFO [src/relay_server.rs:113] DOWNGRADE_START_CHECK: 1800s
[2022-07-05 15:04:29.917281 +00:00] INFO [src/relay_server.rs:122] LIMIT_SPEED: 4Mb/s
[2022-07-05 15:04:29.917284 +00:00] INFO [src/relay_server.rs:132] TOTAL_BANDWIDTH: 1024Mb/s
[2022-07-05 15:04:29.917286 +00:00] INFO [src/relay_server.rs:146] SINGLE_BANDWIDTH: 16Mb/s
s6-rc: info: service hbbs successfully started
s6-rc: info: service hbbr successfully started
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
[2022-07-05 15:05:37.975047 +00:00] INFO [src/relay_server.rs:446] New relay request 8eb2927c-0cc4-49ca-b1c7-64cabc9ad162 from <CLIENT1_IP>:52806
[2022-07-05 15:05:38.940235 +00:00] INFO [src/relay_server.rs:430] Relayrequest 8eb2927c-0cc4-49ca-b1c7-64cabc9ad162 from <CLIENT2_IP>:64362 got paired
[2022-07-05 15:05:38.940288 +00:00] INFO [src/relay_server.rs:436] Both are raw
[2022-07-05 15:06:08.831453 +00:00] INFO [src/relay_server.rs:442] Relay of <CLIENT2_IP>:64362 closed
[2022-07-05 15:07:10.973029 +00:00] INFO [src/relay_server.rs:446] New relay request 54e479e3-26f3-4f9a-a3b1-ab895dfeeb0f from <CLIENT1_IP>:52818
[2022-07-05 15:07:12.938604 +00:00] INFO [src/relay_server.rs:430] Relayrequest 54e479e3-26f3-4f9a-a3b1-ab895dfeeb0f from <CLIENT2_IP>:64689 got paired
[2022-07-05 15:07:12.938630 +00:00] INFO [src/relay_server.rs:436] Both are raw
[2022-07-05 15:07:23.815023 +00:00] INFO [src/relay_server.rs:442] Relay of <CLIENT2_IP>:64689 closed

After pressing the "Connect" button it took 17 seconds at the first try and 25 on the second try, until the "New relay request" message appeared in the log. If it timeouts no log entry will be created.

DNS: (because "it's always DNS") can you try to use the public IP address in both clients and in the RELAY=<PUBLIC_IP> configuration?

I tried to use IP instead of the hostname, but it doesn't make any difference.

encryption key (you've specified RENCRYPTED_ONLY=1): can you confirm that you entered the same key on both clients? (you get the key from id_ed25519.pub)

Yes, I can confirm that the same key was entered on both clients.

@paspo
Copy link
Contributor

paspo commented Jul 5, 2022

I assume the rustdesk server is on a VPS somewhere and the two clients are on different networks.

Is it possible to test if these delays occours with this server and two clients on the same network?

You can also check the timings for direct IP connection.

Another idea is to use a (temporary) rustdesk-server inside the network, to exclude any router/firewall issue.

@KreativeKrise
Copy link
Contributor Author

I assume the rustdesk server is on a VPS somewhere and the two clients are on different networks.

That's correct.

Is it possible to test if these delays occours with this server and two clients on the same network?

If they are on the same network it takes 2-7 seconds.

But there are no log entries, when they connect. Probably because the relay server is not involved?

rustdesk-server    | /package/admin/s6-overlay/libexec/preinit: notice: /var/run is not a symlink to /run, fixing it
rustdesk-server    | s6-rc: info: service hbbs: starting
rustdesk-server    | s6-rc: info: service hbbr: starting
rustdesk-server    | s6-rc: info: service s6rc-oneshot-runner: starting
rustdesk-server    | s6-rc: info: service hbbs successfully started
rustdesk-server    | s6-rc: info: service hbbr successfully started
rustdesk-server    | [2022-07-06 07:14:37.424621 +00:00] INFO [src/relay_server.rs:60] #blacklist(blacklist.txt): 0
rustdesk-server    | [2022-07-06 07:14:37.424629 +00:00] INFO [src/relay_server.rs:75] #blocklist(blocklist.txt): 0
rustdesk-server    | [2022-07-06 07:14:37.424631 +00:00] INFO [src/relay_server.rs:81] Listening on tcp 0.0.0.0:21117
rustdesk-server    | [2022-07-06 07:14:37.424633 +00:00] INFO [src/relay_server.rs:83] Listening on websocket 0.0.0.0:21119
rustdesk-server    | s6-rc: info: service s6rc-oneshot-runner successfully started
rustdesk-server    | [2022-07-06 07:14:37.424634 +00:00] INFO [src/relay_server.rs:85] Start
rustdesk-server    | [2022-07-06 07:14:37.425405 +00:00] INFO [src/relay_server.rs:104] DOWNGRADE_THRESHOLD: 0.66
rustdesk-server    | [2022-07-06 07:14:37.425410 +00:00] INFO [src/relay_server.rs:113] DOWNGRADE_START_CHECK: 1800s
rustdesk-server    | [2022-07-06 07:14:37.425412 +00:00] INFO [src/relay_server.rs:122] LIMIT_SPEED: 4Mb/s
rustdesk-server    | [2022-07-06 07:14:37.425414 +00:00] INFO [src/relay_server.rs:132] TOTAL_BANDWIDTH: 1024Mb/s
rustdesk-server    | [2022-07-06 07:14:37.425438 +00:00] INFO [src/relay_server.rs:146] SINGLE_BANDWIDTH: 16Mb/s
rustdesk-server    | [2022-07-06 07:14:37.426296 +00:00] INFO [src/peer.rs:82] DB_URL=./db_v2.sqlite3
rustdesk-server    | s6-rc: info: service fix-attrs: starting
rustdesk-server    | s6-rc: info: service fix-attrs successfully started
rustdesk-server    | s6-rc: info: service legacy-cont-init: starting
rustdesk-server    | s6-rc: info: service legacy-cont-init successfully started
rustdesk-server    | s6-rc: info: service legacy-services: starting
rustdesk-server    | s6-rc: info: service legacy-services successfully started
rustdesk-server    | [2022-07-06 07:14:37.455201 +00:00] INFO [src/rendezvous_server.rs:94] serial=0
rustdesk-server    | [2022-07-06 07:14:37.455214 +00:00] INFO [src/common.rs:41] rendezvous-servers=[]
rustdesk-server    | [2022-07-06 07:14:37.455217 +00:00] INFO [src/rendezvous_server.rs:96] Listening on tcp/udp 0.0.0.0:21116
rustdesk-server    | [2022-07-06 07:14:37.455218 +00:00] INFO [src/rendezvous_server.rs:97] Listening on tcp 0.0.0.0:21115, extra port for NAT test
rustdesk-server    | [2022-07-06 07:14:37.455220 +00:00] INFO [src/rendezvous_server.rs:98] Listening on websocket 0.0.0.0:21118
rustdesk-server    | [2022-07-06 07:14:37.455236 +00:00] INFO [libs/hbb_common/src/udp.rs:33] Receive buf size of udp 0.0.0.0:21116: Ok(212992)
rustdesk-server    | [2022-07-06 07:14:37.455330 +00:00] INFO [src/common.rs:120] Private/public key written to id_ed25519/id_ed25519.pub
rustdesk-server    | [2022-07-06 07:14:37.455336 +00:00] INFO [src/rendezvous_server.rs:1126] Key: IObetpORKrENSDkUNNuyvKIkHCOdUMNFY8+89ZDKIEo=
rustdesk-server    | [2022-07-06 07:14:37.455341 +00:00] INFO [src/common.rs:41] relay-servers=["192.168.1.86:21117"]
rustdesk-server    | [2022-07-06 07:14:37.455364 +00:00] INFO [src/rendezvous_server.rs:135] ALWAYS_USE_RELAY=N
rustdesk-server    | [2022-07-06 07:14:37.455373 +00:00] INFO [src/rendezvous_server.rs:155] Start
rustdesk-server    | [2022-07-06 07:16:05.397420 +00:00] INFO [src/peer.rs:100] update_pk 487153153 192.168.1.109:60324 [100, 53, 100, 100, 48, 49, 49, 57, 45, 98, 52, 97, 55, 45, 52, 97, 57, 50, 45, 57, 48, 99, 50, 45, 50, 99, 102, 52, 56, 55, 99, 57, 102, 54, 49, 98] [52, 185, 79, 15, 251, 177, 102, 163, 166, 41, 255, 99, 118, 166, 191, 249, 182, 19, 98, 140, 20, 64, 227, 101, 175, 46, 23, 195, 167, 194, 50, 201]
rustdesk-server    | [2022-07-06 07:16:56.928150 +00:00] INFO [src/peer.rs:100] update_pk 1108110453 192.168.1.100:60628 [99, 49, 98, 52, 52, 98, 57, 98, 45, 54, 53, 101, 48, 45, 52, 53, 102, 57, 45, 97, 49, 48, 98, 45, 100, 101, 100, 53, 54, 52, 48, 49, 50, 56, 49, 53] [82, 116, 90, 217, 157, 242, 3, 15, 137, 111, 82, 253, 109, 167, 217, 132, 48, 82, 120, 173, 184, 243, 126, 185, 103, 0, 80, 77, 130, 223, 247, 238]

You can also check the timings for direct IP connection.

I enabled direct IP connection and opened port 21118/tcp on the client. It takes 2-5 seconds to connect.

@paspo
Copy link
Contributor

paspo commented Jul 6, 2022

I enabled direct IP connection and opened port 21118/tcp on the client. It takes 2-5 seconds to connect.

This is our baseline, we can't expect anything faster than that. In this case, no server is involved.

If they are on the same network it takes 2-7 seconds.

So the previous case plus the time for hole-punching.

But there are no log entries, when they connect. Probably because the relay server is not involved?

The log entries are from the relay server (hbbr) which you don't use because both clients are on the same network. In this scenario, only hbbs is used.

To recap:

  1. direct connection: 2-5 seconds
  2. external server, clients on same network (no relay): 2-7 seconds
  3. external server, clients on different network (relay): 20-30 seconds and timeouts

At this point we can exclude the clients and the internal network.
We need another test case: external server with clients on same network (the same network on 2.) but with relay.
To test that, add ALWAYS_USE_RELAY=Y to the environment of the docker container, or expose the ports without network_mode: host.

@rustdesk
Copy link
Owner

rustdesk commented Jul 6, 2022

  1. 2-5 seconds

I can connect to my PC in office from home with less than 1 second, public server (AWS, before it is vultr, Thanks for AWS's free credit) in Singapore.

@paspo
Copy link
Contributor

paspo commented Jul 6, 2022

I can connect to my PC in office from home with less than 1 second, public server in Singapore.

We should have a talk about connection latency and speeds around the world.

From my office I can ping my external rustdesk server in 16ms (avg), I have 100mbit (down) / 30 mbit (up) FWA. This here (northern Italy) is a "good connection" (except with heavy rains, which causes disconnections).
I can always establish a connection in <5 sec. Also the VPS running rustdesk server is on the "low spec" tier. Well, on the bottom of that tier.

In Italy, FTTC is a hit/miss (mostly miss because of the long copper connection), FTTH is mostly unavailable outside big cities.

Just for reference: singapore vs italy

@rustdesk
Copy link
Owner

rustdesk commented Jul 6, 2022

singapore vs italy

Interesting.

@KreativeKrise
Copy link
Contributor Author

We need another test case: external server with clients on same network (the same network on 2.) but with relay.
To test that, add ALWAYS_USE_RELAY=Y to the environment of the docker container, or expose the ports without network_mode: host.

When I do that, then I get the message Failed to connect via rendezvous server: Please try later after ~35 seconds on CLIENT1. While CLIENT1 tries to connect, I can see the the window to accept/decline the connection on CLIENT2 flashing up for a few milliseconds every ~5 seconds.

I tried it with both docker-compose configurations I posted at the beginning, except I added ALWAYS_USE_RELAY=Y.

We should have a talk about connection latency and speeds around the world.

Connection CLIENT1 and CLIENT2 (same network): 250Mbit down / 40 Mbit up, 15ms ping to external rustdesk server
Connection CLIENT3 (other network): 200Mbit (down) / 100 Mbit (up) and 9ms ping to external rustdesk server

@paspo
Copy link
Contributor

paspo commented Jul 6, 2022

Just to test all the cases, can you try this configuration:

version: '3'

services:
  rustdesk-server:
    container_name: rustdesk-server
    ports:
      - 21115:21115
      - 21116:21116
      - 21116:21116/udp
      - 21117:21117
      - 21118:21118
      - 21119:21119
    image: rustdesk/rustdesk-server-s6:latest
    environment:
      - "RELAY=<PUBLIC_IP>:21117"
      - "ENCRYPTED_ONLY=1"
    volumes:
      - ./data:/data
    restart: unless-stopped

which is the second one you mentioned (#54 (comment)), without the ALWAYS_USE_RELAY=Y. This should always use the relay anyway.

@KreativeKrise
Copy link
Contributor Author

I tried both configurations with both Clients at the same network and an external rustdesk server:

With Exposing ports and without ALWAYS_USE_RELAY=Y it takes between 8 and 10 seconds
With network_mode: host and without ALWAYS_USE_RELAY=Y it takes ~5 seconds

@paspo
Copy link
Contributor

paspo commented Jul 6, 2022

Recap:

  1. direct connection: 2-5 seconds
  2. external server, clients on same network (no relay): 2-7 seconds
  3. external server, clients on same network (relay in --net=host): ~5 seconds
  4. external server, clients on same network (relay in --net=bridge): 8-10 seconds
  5. external server, clients on different network (relay): 20-30 seconds and timeouts

Am I correct?

@KreativeKrise
Copy link
Contributor Author

KreativeKrise commented Jul 6, 2022

  1. external server, clients on same network (no relay): 2-7 seconds

It was internal server, clients on same network

But the rest is correct.

@paspo
Copy link
Contributor

paspo commented Jul 6, 2022

It was internal server, clients on same network

ok, noted

I can safely say that:

  • the problem is not on the VPS, because of point 3 and 4 (connection works with acceptable timing)
  • for the same reason we can exclude hbbs, hbbr
  • (timing is penalized with bridge networking but you have network isolation, it's your choice)
  • looks like the different network is causing troubles

This is somewhat strange: it's not a slow connection...

Maybe some firewall rules? an aggressive IDS/IPS?
Can you try a different network?

@KreativeKrise
Copy link
Contributor Author

Maybe some firewall rules?

There are no special rules, so I would say that there is no problem.

Can you try a different network?

I did another test with the RustDesk app on my mobile phone over LTE. I tried to connect to the network with the 2 clients and to the network with the remote client. On both it takes 20-30 seconds or it times out.

an aggressive IDS/IPS?

Aggressive in which way? I tried it with 3 different providers:
ISP1 <-> ISP2
ISP2 <-> ISP3
ISP3 <-> ISP1

@rustdesk
Copy link
Owner

rustdesk commented Jul 11, 2022

@KreativeKrise some one reported old version works well with out big delay. Could you please try out rustdesk/rustdesk-server:1.0.0?
https://hub.docker.com/layers/251435140/rustdesk/rustdesk-server/1.0.0/images/sha256-714b474dbcfa4fa977634bb8a7256727765a15364ef619dfc85b673ebee40f3a?context=repo

@KreativeKrise
Copy link
Contributor Author

KreativeKrise commented Jul 11, 2022

Of course, with pleasure. But unfortunately, I only get the message Registered email required (-m option). Please pay and register on https://rustdesk.com/server..

version: '3'

networks:
  rustdesk-net:
    external: false

services:
  hbbs:
    container_name: hbbs
    ports:
      - 21115:21115
      - 21116:21116
      - 21116:21116/udp
      - 21118:21118
    image: rustdesk/rustdesk-server:1.0.0
    command: hbbs -r <PUBLIC_IP>:21117
    volumes:
      - ./hbbs:/root
    networks:
      - rustdesk-net
    depends_on:
      - hbbr
    restart: unless-stopped

  hbbr:
    container_name: hbbr
    ports:
      - 21117:21117
      - 21119:21119
    image: rustdesk/rustdesk-server:1.0.0
    command: hbbr
    volumes:
      - ./hbbr:/root
    networks:
      - rustdesk-net
    restart: unless-stopped

@rustdesk
Copy link
Owner

hbbs -r <PUBLIC_IP>:21117 -m demo
hbbr -m demo

@KreativeKrise
Copy link
Contributor Author

KreativeKrise commented Jul 11, 2022

Client1 and Client2 on different networks:
The first connection takes 15-20 seconds. When reconnecting, however, only 2-3 seconds.

Client1 and Client2 on same network:
The first connection takes 6-7 seconds. When reconnecting, it connects instantly.

@rustdesk
Copy link
Owner

Thanks

@rustdesk
Copy link
Owner

rustdesk commented Jul 12, 2022

@KreativeKrise Could you help test rustdesk/rustdesk-server:1.1.6? -m demo is not needed any more.

@KreativeKrise
Copy link
Contributor Author

The connection time is identical to version 1.0.0.

@rustdesk
Copy link
Owner

Thanks~

@jhotmann
Copy link

1.1.6 hugely improved my connection times (nearly instant instead of ~30 seconds). I'm connecting to a Ubuntu 18.04 machine from MacOS. Server is running in docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants