[Bug]: Client tears down a healthy Tailscale socket to "upgrade" to LAN, then falls back — remote connections flap #24516
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.3553and0.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
/wssessions, 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
/wssession 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 emitsBetterRouteAvailable. BetterRouteAvailablereturnsreset, 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.
tanstack-source added labelsbug
Sign in to join this conversation.
Another case of this switching, on stable
0.1.7. Two points differ from the original report: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 aslan(rank 1) above the directtailnetroute (rank 2).lanroute 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 tolanagain. 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.7stable, macOS arm64 client and server, servernetwork-accessible, paired with T3 Connect.Steps to reproduce
network-accessibleon host A. Host A has a LAN address and a Tailscale address.Client trace (addresses redacted)
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.