feat(connect): t3 connect checks that other devices can reach this machine #22172
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 10 commits into
main fromrefs/pull/22172/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/server/src/cloud/ConnectReachability.ts lines 87 to 87OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +67,21 @@67+ "The server has not set up a T3 Connect tunnel.",68+ "Run `t3 connect`, then restart the server (`t3 service restart`) so it applies the link.",69+ );70+ }71+ if (connector === null) {72+ return fail(73+ "connector_not_running",74+ "The tunnel client (cloudflared) is not running.",75+ "Restart T3 Code. If it stays down, check the server log for relay client errors.",76+ );77+ }78+ const status = endpoint?.kind === "status" ? endpoint.status : null;79+ if (status === 200) {80+ return {81+ status: "reachable",82+ checkedAt,83+ readyConnections: connector.readyConnections ?? 0,84+ protocol: connector.protocol,85+ };86+ }87+ if (facts.edgeReachable === false) {
- apps/server/src/cli/connect.ts lines 669 to 673OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -576,3 +666,8 @@576666 secrets.get(PUBLISH_AGENT_ACTIVITY_SECRET),577667 secrets.get(CLOUD_LINK_REVOKED),578668 relayClient.resolve,669+ CliState.readCliDesiredCloudLink.pipe(670+ Effect.flatMap((desired) =>671+ desired ? checkLiveReachability() : Effect.succeed(null),672+ ),673+ ),apps/server/src/cloud/ConnectReachability.ts lines 87 to 96OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +76,21 @@76+ );77+ }78+ const status = endpoint?.kind === "status" ? endpoint.status : null;79+ if (status === 200) {80+ return {81+ status: "reachable",82+ checkedAt,83+ readyConnections: connector.readyConnections ?? 0,84+ protocol: connector.protocol,85+ };86+ }87+ if (facts.edgeReachable === false) {88+ return fail(89+ "edge_unreachable",90+ `Cloudflare's tunnel port (${TUNNEL_EDGE_PORT}) times out from this machine.`,91+ exitNode92+ ? `tailscale set --exit-node= (or allow outbound ${TUNNEL_EDGE_PORT} on that network)`93+ : `Allow outbound TCP and UDP port ${TUNNEL_EDGE_PORT}, or turn off the VPN or firewall that blocks it.`,94+ exitNodeHint(exitNode) ?? "A VPN, proxy, or firewall may block it.",95+ );96+ }apps/web/src/components/settings/ConnectionsSettings.tsx line 1910OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1885,4 +1905,6 @@18851905 linkRevoked18861906 ? "This environment was removed from T3 Connect. Turn it on to link it again."18871907 : managedTunnelActive1888- ? "This environment is available to your other devices through T3 Connect."1908+ ? reachability?.status === "unreachable"1909+ ? "T3 Connect is on, but other devices cannot reach this environment."1910+ : "This environment is available to your other devices through T3 Connect."packages/tailscale/src/tailscale.ts lines 326 to 329OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -288,0 +309,21 @@309+ readonly online: boolean;310+}311+312+/**313+ * `ExitNodeStatus` is present only while an exit node is in use, but it has no314+ * name. The name comes from the peer marked `ExitNode: true`.315+ */316+export const parseTailscaleExitNode = (317+ rawStatusJson: string,318+): Effect.Effect<TailscaleExitNode | null, TailscaleStatusParseError> =>319+ decodeTailscaleExitNodeJson(rawStatusJson).pipe(320+ Effect.mapError((cause) => new TailscaleStatusParseError({ cause })),321+ Effect.map((parsed) => {322+ if (parsed.ExitNodeStatus === undefined) return null;323+ const peer = Object.values(parsed.Peer ?? {}).find(324+ (candidate) => candidate.ExitNode === true,325+ );326+ const hostName = typeof peer?.HostName === "string" ? peer.HostName.trim() : "";327+ const dnsLabel = typeof peer?.DNSName === "string" ? (peer.DNSName.split(".")[0] ?? "") : "";328+ return {329+ name: hostName || dnsLabel || null,
- apps/server/src/cloud/ConnectReachability.ts line 295Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +257,21 @@257+ last.cause !== result.cause),258+ });259+ if (!changed || (result.status === "unreachable" && result.cause === "not_linked")) {260+ return result;261+ }262+ if (result.status === "unreachable") {263+ // A connector that has not connected yet is usually still starting; the264+ // runtime restarts it, and an unreachable edge is reported as its own cause.265+ const log = result.cause === "connector_not_ready" ? Effect.logWarning : Effect.logError;266+ yield* log(`\n${formatReachabilityFailure(result)}`).pipe(267+ Effect.annotateLogs({ cause: result.cause }),268+ );269+ } else {270+ yield* Effect.logInfo(271+ `T3 Connect is reachable from other devices. ${formatConnectReachable(result)}`,272+ );273+ }274+ return result;275+ }).pipe(Effect.withSpan("ConnectReachability.check"));276+277+ yield* runtime.readinessChanged.pipe(
- apps/server/src/cloud/ConnectReachability.ts lines 98 to 99Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +72,21 @@72+ return fail(73+ "connector_not_running",74+ "The tunnel client (cloudflared) is not running.",75+ "Restart T3 Code. If it stays down, check the server log for relay client errors.",76+ );77+ }78+ const status = endpoint?.kind === "status" ? endpoint.status : null;79+ if (status === 200) {80+ return {81+ status: "reachable",82+ checkedAt,83+ readyConnections: connector.readyConnections ?? 0,84+ protocol: connector.protocol,85+ };86+ }87+ // The edge test is TCP only. With QUIC connections up, or with DNS already failing, a88+ // failed TCP test would hide the real cause.89+ if (90+ facts.edgeReachable === false &&91+ !(connector.readyConnections && connector.readyConnections > 0) &&92+ endpoint?.kind !== "dns_failed"
- apps/server/src/cloud/ConnectReachability.ts line 217Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +188,21 @@188+ {189+ /** Runs a check now. The server also runs one when the tunnel's readiness changes. */190+ readonly check: Effect.Effect<EnvironmentConnectReachability>;191+ readonly latest: Effect.Effect<Option.Option<EnvironmentConnectReachability>>;192+ }193+>()("t3/cloud/ConnectReachability") {}194+195+const make = Effect.gen(function* () {196+ const runtime = yield* ManagedEndpointRuntime.CloudManagedEndpointRuntime;197+ const secrets = yield* ServerSecretStore.ServerSecretStore;198+ const httpClient = yield* HttpClient.HttpClient;199+ const latestRef = yield* Ref.make(Option.none<EnvironmentConnectReachability>());200+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;201+ const readExitNode = readTailscaleExitNode.pipe(202+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),203+ Effect.orElseSucceed(() => null),204+ );205+206+ const probeEndpoint = (hostname: string) =>207+ httpClient.get(`https://${hostname}/.well-known/t3/environment`).pipe(208+ Effect.map((response): EndpointProbe => ({ kind: "status", status: response.status })),
- apps/server/src/cloud/ConnectReachability.ts lines 300 to 304Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +269,21 @@269+ yield* log(`\n${formatReachabilityFailure(result)}`).pipe(270+ Effect.annotateLogs({ cause: result.cause }),271+ );272+ } else {273+ yield* Effect.logInfo(274+ `T3 Connect is reachable from other devices. ${formatConnectReachable(result)}`,275+ );276+ }277+ return result;278+ }).pipe(Effect.withSpan("ConnectReachability.check"));279+280+ yield* runtime.readinessChanged.pipe(281+ Stream.debounce(READINESS_CHANGE_DEBOUNCE),282+ Stream.runForEach(() => check),283+ Effect.forkScoped,284+ );285+ yield* Effect.sleep(RECHECK_INTERVAL).pipe(286+ Effect.andThen(check),287+ Effect.forever,288+ Effect.forkScoped,289+ );
- apps/server/src/cloud/ConnectReachability.ts lines 86 to 91Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -0,0 +71,21 @@71+ return fail(72+ "not_linked",73+ "The server has not set up a T3 Connect tunnel.",74+ "Run `t3 connect`, then restart the server (`t3 service restart`) so it applies the link.",75+ );76+ }77+ if (connector === null) {78+ return fail(79+ "connector_not_running",80+ "The tunnel client (cloudflared) is not running.",81+ "Restart T3 Code. If it stays down, check the server log for relay client errors.",82+ );83+ }84+ const status = endpoint?.kind === "status" ? endpoint.status : null;85+ if (status === 200) {86+ return {87+ status: "reachable",88+ checkedAt,89+ readyConnections: connector.readyConnections ?? 0,90+ protocol: connector.protocol,91+ };docs/user/t3-connect-troubleshooting.md lines 15 to 16OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -0,0 +1,16 @@1+# T3 Connect troubleshooting2+3+A T3 Connect connection goes through four parts, in this order:4+5+**This device** reaches T3 Connect over the internet.6+**T3 Connect** checks your sign-in and the host's link.7+**The host's tunnel** (cloudflared on the host) carries the request to the host.8+**T3 Code on the host** answers.9+10+When a connection fails, open **Settings > Connections**, find the environment,11+and select **Details**. The first part marked as failed is the cause. Find its12+section below.13+14+To see the host's side, run `t3 connect status` on the host, or open15+**Settings > Connections** on the host. Both check that other devices can reach16+the host through T3 Connect, and say why not. `t3 connect` runs the same checkpackages/client-runtime/src/connection/diagnosis.ts lines 255 to 256Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -205,0 +236,21 @@236+ case "tls":237+ case "refused":238+ case "timeout":239+ case "unknown":240+ return "the-t3-connect-address-does-not-resolve-or-answer";241+ case null:242+ break;243+ }244+ const onThisDevice =245+ failure?.reason === "network" ||246+ failure?.reason === "transport" ||247+ failure?.reason === "timeout";248+ switch (located.hop) {249+ case "device":250+ return "this-device-cant-reach-t3-connect";251+ case "relay":252+ return failure?.reason === "authentication"253+ ? "sign-in-account-or-link-problems"254+ : "this-device-cant-reach-t3-connect";255+ case "tunnel":256+ return onThisDevice ? "this-device-cant-reach-t3-connect" : "the-hosts-tunnel-is-offline";packages/client-runtime/src/connection/diagnosis.ts lines 257 to 258OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -205,0 +238,21 @@238+ case "timeout":239+ case "unknown":240+ return "the-t3-connect-address-does-not-resolve-or-answer";241+ case null:242+ break;243+ }244+ const onThisDevice =245+ failure?.reason === "network" ||246+ failure?.reason === "transport" ||247+ failure?.reason === "timeout";248+ switch (located.hop) {249+ case "device":250+ return "this-device-cant-reach-t3-connect";251+ case "relay":252+ return failure?.reason === "authentication"253+ ? "sign-in-account-or-link-problems"254+ : "this-device-cant-reach-t3-connect";255+ case "tunnel":256+ return onThisDevice ? "this-device-cant-reach-t3-connect" : "the-hosts-tunnel-is-offline";257+ case "server":258+ return "the-tunnel-works-but-t3-code-does-not-answer";
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.



macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed