Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Client tears down a healthy Tailscale socket to "upgrade" to LAN, then falls back — remote connections flap #24516

Openthekvn(GitHub profile, opens in a new tab) opened this issue 1 comment

Summary

When a remote client has both a LAN and a Tailscale route to the same environment (the server is network-accessible on 0.0.0.0, so DirectEndpoints advertises both), the client keeps tearing down a healthy Tailscale WebSocket to "upgrade" to LAN. The LAN connection then doesn't establish, the client falls back to Tailscale, and the cycle repeats after the route cooldown. From the user's side, remote connections look unreliable: frequent disconnects and resyncs.

Environment

  • Server: desktop app, nightly 0.1.3-nightly.20261023.3553 and 0.1.3-nightly.20261024.3630, macOS arm64, serverExposureMode: network-accessible
  • Client: iOS, same Wi-Fi subnet as the server, Tailscale active on both (direct path, not DERP)

What the server traces show (≈80 min window)

  • 12 /ws sessions, all from one auth session (one phone), alternating between the Tailscale host and the LAN host.
  • Lifetimes: 14, 43, 45, 51, 59, 70, 93, 122, 139, 240, 461 s. Every socket closed cleanly from the client side.
  • Each new Tailscale /ws session starts within ~1 s of a successful (200) LAN preflight to /.well-known/t3/environment.
  • Only 2 of the 12 sessions actually landed on LAN (17 s and 139 s). Most "upgrades" end with a fresh Tailscale socket.

Client logic involved (runtime-*.js)

  • Route rank {loopback:0, lan:1, tailnet:2, vpn:2, public:3, ssh:4, relay:5}.
  • While on a non-best route, better routes are preflighted every 60 seconds (and on wake/network change). The first successful preflight emits BetterRouteAvailable.
  • BetterRouteAvailable returns reset, closing the current socket before the new route is known to work.
  • If the established route isn't the preferred one, the preferred route gets a 3e5 (5 min) cooldown, after which the loop repeats.

Expected

  • Make-before-break: keep the current socket until the better route has fully connected (ticket, upgrade, initial sync), then switch.
  • A route that passes preflight but fails to establish should back off longer (exponential) instead of a fixed 5 min.
  • Optionally, treat a direct Tailscale path on the same LAN as equivalent to LAN, or let users pin a route (#10940 mentions manual pinning).

Workaround

Rejecting port 3773 on the LAN interfaces with pf, so only the Tailscale route passes preflight, stops the switching.

  1. Another case of this switching, on stable 0.1.7. Two points differ from the original report:

    1. The "LAN" route is not on the client's LAN. The remote's home address (192.168.0.x) is reachable from the client only through a Tailscale subnet route. The remote is in another country. Both routes have the same round trip of about 260 ms. The client still ranks the subnet-routed address as lan (rank 1) above the direct tailnet route (rank 2).
    2. Both routes connect successfully, and the client still switches. Every switch to the lan route connects (preflight 200, websocket ticket 200, sync). About 60 seconds later the client switches back to the Tailscale route. About 4 minutes after that, it switches to lan again. A make-before-break change would hide each reset, but the client would still switch, resubscribe, and resync twice every 5 minutes.

    Area: apps/web (client connection runtime) Impact: Major degradation or frequent failure. Each switch interrupts all subscriptions for 1 to 3 seconds. Version: desktop 0.1.7 stable, macOS arm64 client and server, server network-accessible, paired with T3 Connect.

    Steps to reproduce

    1. Run the server network-accessible on host A. Host A has a LAN address and a Tailscale address.
    2. On another node on host A's LAN, advertise host A's LAN address as a Tailscale subnet route.
    3. On client B, on a different network, accept Tailscale routes and pair with host A.
    4. Leave the client connected for 10 minutes.

    Client trace (addresses redacted)

    11:01:38 preflight http://192.168.0.x:3773  200 -> signal, learnRoutes, setState
    11:02:44 preflight http://100.x.y.z:3773    200 -> signal, learnRoutes, setState
    11:06:49 preflight http://192.168.0.x:3773  200 -> switch
    11:07:53 preflight http://100.x.y.z:3773    200 -> switch
    11:11:58 preflight http://192.168.0.x:3773  200 -> switch
    11:13:03 preflight http://100.x.y.z:3773    200 -> switch

    When Tailscale is stopped on the client, both preflights time out and the client stays on the T3 Connect relay with no switches.

    Workaround: on the subnet router, drop TCP 3773 to the routed address (iptables -t raw -I PREROUTING -i tailscale0 -d <addr> -p tcp --dport 3773 -j DROP). Then only the Tailscale route passes preflight. I watched the client for 11 minutes after this change and it did not switch.

    The suggestion above to treat a direct Tailscale path as equal to LAN would also fix this case. Would you accept a PR for that? One option: switch to a higher-ranked route only when its measured preflight time is clearly lower than the active route's.

  2. tanstack-source added labelsbug

Sign in to join this conversation.