kaichaosun / rlt

Localtunnel implementation in Rust, expose local API to the public.
MIT License
87 stars 11 forks source link

tunnel stop working after a while #36

Open gdesmott opened 1 month ago

gdesmott commented 1 month ago

It all works perfectly fine, but after a while if the tunnel is not used it stops working.

Here are the logs (using #35) on the server:

Aug 05 11:51:02 urithiru localtunnel[923346]: [2024-08-05T09:51:02Z TRACE mio::poll] registering event source with poller: token=Token(140044589388288), interests=READABLE | WRITABLE
Aug 05 11:51:02 urithiru localtunnel[923346]: [2024-08-05T09:51:02Z INFO  localtunnel_server] Accepted a new proxy request
Aug 05 11:51:02 urithiru localtunnel[923346]: [2024-08-05T09:51:02Z DEBUG localtunnel_server::proxy] Request hostname: meuth.karapulse.org
Aug 05 11:51:02 urithiru localtunnel[923346]: [2024-08-05T09:51:02Z DEBUG localtunnel_server::state] try using socket 9/100

Aug 05 11:52:02 urithiru localtunnel[923346]: [2024-08-05T09:52:02Z TRACE mio::poll] deregistering event source from poller
Aug 05 11:52:02 urithiru localtunnel[923346]: [2024-08-05T09:52:02Z ERROR localtunnel_server] Failed to serve connection: hyper::Error(IncompleteMessage)
Aug 05 11:52:02 urithiru localtunnel[923346]: [2024-08-05T09:52:02Z TRACE mio::poll] deregistering event source from poller

Nothing is log in the app so I think the server does not send anything to it.

Also the sockets are not given back to the pool so it will eventually run out of connections.

Any idea what could cause this problem or how to debug it?

kaichaosun commented 1 month ago

It may relates to the network changes broken the tunnel, there is no logic to handle this scenario.

gdesmott commented 1 month ago

It may relates to the network changes broken the tunnel, there is no logic to handle this scenario.

I don't think so. The server has a static IP and my app is running on my desktop whose (public) IP is not changing much.

It' quite easy to reproduce, I just have to not use the tunnel for 20 minutes or so.

gdesmott commented 1 month ago

My app is establishing a tunnel using the localtunnel_client::open_tunnel() API

Actually I can reproduce this problem using the localtunnel CLI client as well:

@kaichaosun that does work for you?

gdesmott commented 1 month ago

Here are nginx logs when this problem happens. Not sure what it means exactly.

2024/08/05 15:24:31 [error] 935764#935764: *48 connect() failed (111: Connection refused) while connecting to upstream, client: 78.129.103.27, server: *.karapulse.org, request: "GET / HTTP/1.1", upstream: "http://[::1]:3001/", host: "soebly.karapulse.org"
2024/08/05 15:24:31 [debug] 935764#935764: *48 http next upstream, 2
2024/08/05 15:24:31 [debug] 935764#935764: *48 free rr peer 2 4
2024/08/05 15:24:31 [warn] 935764#935764: *48 upstream server temporarily disabled while connecting to upstream, client: 78.129.103.27, server: *.karapulse.org, request: "GET / HTTP/1.1", upstream: "http://[::1]:3001/", host: "soebly.karapulse.org"
gdesmott commented 1 month ago

So I guess this may actually be a nginx problem?

@kaichaosun do you have a nginx configuration working reliably by any chance? Here is mine.

server {
  listen 80;
  listen [::]:80;
  server_name *.karapulse.org;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl;
  server_name tunnel.karapulse.org;

  access_log /var/log/nginx/karapulse-tunnel.access.log;
  error_log /var/log/nginx/karapulse-tunnel.error.log debug;

  ssl_certificate /etc/letsencrypt/live/karapulse.org/fullchain.pem;
  ssl_certificate_key  /etc/letsencrypt/live/karapulse.org/privkey.pem;
  include /etc/letsencrypt/options-ssl-nginx.conf;
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

  location / {
    proxy_pass http://localhost:3000;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
  }
}

server {
  listen 443 ssl;
  server_name *.karapulse.org;

  access_log /var/log/nginx/karapulse-tunnel.access.log;
  error_log /var/log/nginx/karapulse-tunnel.error.log debug;

  ssl_certificate /etc/letsencrypt/live/karapulse.org/fullchain.pem;
  ssl_certificate_key  /etc/letsencrypt/live/karapulse.org/privkey.pem;
  include /etc/letsencrypt/options-ssl-nginx.conf;
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

  location / {
    proxy_pass http://localhost:3001;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
  }
}
gdesmott commented 1 month ago

So I guess this may actually be a nginx problem?

Actually maybe not.

I have the same problem when trying to connect directly to the tunnel server by connecting directly to port 3001 and by passing nginx .

kaichaosun commented 1 month ago

@gdesmott I haven't been running it for quite a while, will look into it when I'm free. For now you can probably restart the connection on client side once a while.