GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(client): explain possible network blocking for T3 Connect (#9783) · pingdotgg/t3code@2dca7a1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components/settings
    • ConnectionsSettings.tsx
  • packages/client-runtime/src
    • authorization
      • service.ts
    • connection
      • errors.test.ts
      • errors.ts
      • supervisor.test.ts
      • supervisor.ts
    • errors
      • network.ts
    • relay
      • discovery.test.ts
      • managedRelay.test.ts
      • managedRelay.ts
    • rpc
      • session.test.ts
      • session.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/settings/ConnectionsSettings.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/settings/ConnectionsSettings.tsx
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,9 @@ function SavedBackendListRow({
15241524
) : null}
15251525
{environment.connection.error && !resumingServerUpdate ? (
15261526
<p className="flex min-w-0 items-center gap-2 text-destructive text-xs">
1527-
<span className="truncate">{connectionStatusText(environment.connection)}</span>
1527+
<span className="min-w-0 break-words">
1528+
{connectionStatusText(environment.connection)}
1529+
</span>
15281530
{errorTraceId ? (
15291531
<button
15301532
type="button"
Collapse file

‎packages/client-runtime/src/authorization/service.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/authorization/service.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ function mapDpopSocketError(error: RemoteEnvironmentAuthError | ConnectionAttemp
8080

8181
const fetchDescriptor = Effect.fn("clientRuntime.connection.remote.fetchDescriptor")(function* (
8282
httpBaseUrl: string,
83+
connectionMethod: ClientConnectionMethod,
8384
) {
8485
return yield* fetchRemoteEnvironmentDescriptor({ httpBaseUrl }).pipe(
85-
Effect.mapError(mapRemoteEnvironmentError),
86+
Effect.mapError((error) => mapRemoteEnvironmentError(error, connectionMethod)),
8687
);
8788
});
8889

@@ -119,7 +120,7 @@ export const make = Effect.gen(function* () {
119120
cachedDescriptor.validatedAtEpochMs + BEARER_DESCRIPTOR_CACHE_TTL_MS > now;
120121
const descriptor = canReuseDescriptor
121122
? cachedDescriptor.descriptor
122-
: yield* fetchDescriptor(input.httpBaseUrl).pipe(
123+
: yield* fetchDescriptor(input.httpBaseUrl, input.connectionMethod).pipe(
123124
Effect.provideService(HttpClient.HttpClient, httpClient),
124125
);
125126
if (descriptor.environmentId !== input.expectedEnvironmentId) {
@@ -252,7 +253,7 @@ export const make = Effect.gen(function* () {
252253
"connection.remote_token_cache": "miss",
253254
});
254255
const bootstrap = yield* input.obtainBootstrap;
255-
const descriptor = yield* fetchDescriptor(bootstrap.endpoint.httpBaseUrl).pipe(
256+
const descriptor = yield* fetchDescriptor(bootstrap.endpoint.httpBaseUrl, "relay").pipe(
256257
Effect.provideService(HttpClient.HttpClient, httpClient),
257258
Effect.withSpan("environment.authorization.descriptor"),
258259
);
Collapse file

‎packages/client-runtime/src/connection/errors.test.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/connection/errors.test.ts
+58-2Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
import { EnvironmentAuthInvalidError } from "@t3tools/contracts";
2-
import { RelayAuthInvalidError } from "@t3tools/contracts/relay";
2+
import {
3+
RelayAuthInvalidError,
4+
RelayEnvironmentEndpointTimedOutError,
5+
} from "@t3tools/contracts/relay";
36
import { describe, expect, it } from "@effect/vitest";
47

5-
import { mapManagedRelayError, mapRemoteDpopEnvironmentError } from "./errors.ts";
8+
import {
9+
mapManagedRelayError,
10+
mapRemoteDpopEnvironmentError,
11+
mapRemoteEnvironmentError,
12+
} from "./errors.ts";
613
import { DPOP_RETRY_HINT, DPOP_UNKNOWN_HINT } from "../relay/errorPresentation.ts";
714
import { ManagedRelayRequestFailedError } from "../relay/managedRelay.ts";
15+
import { NETWORK_BLOCKING_HINT } from "../errors/network.ts";
16+
import { RemoteEnvironmentAuthFetchError, RemoteEnvironmentAuthTimeoutError } from "../rpc/http.ts";
817

918
describe("mapManagedRelayError", () => {
19+
it("keeps a timeout reported by the relay distinct from a local network failure", () => {
20+
const relayError = new RelayEnvironmentEndpointTimedOutError({
21+
code: "environment_endpoint_timed_out",
22+
traceId: "trace-server-timeout",
23+
});
24+
const mapped = mapManagedRelayError(
25+
new ManagedRelayRequestFailedError({
26+
action: "connect relay environment",
27+
cause: relayError,
28+
relayError,
29+
}),
30+
);
31+
expect(mapped).toMatchObject({
32+
reason: "timeout",
33+
detail: "Relay timed out while contacting the environment endpoint.",
34+
traceId: "trace-server-timeout",
35+
});
36+
});
37+
1038
it("presents clock skew as one possible cause for a generic DPoP error", () => {
1139
const mapped = mapManagedRelayError(
1240
new ManagedRelayRequestFailedError({
@@ -48,6 +76,34 @@ describe("mapManagedRelayError", () => {
4876
});
4977

5078
describe("mapRemoteDpopEnvironmentError", () => {
79+
it("keeps relay descriptor auth failures distinct from DPoP proof failures", () => {
80+
const error = new EnvironmentAuthInvalidError({
81+
code: "auth_invalid",
82+
reason: "invalid_credential",
83+
traceId: "trace-descriptor",
84+
});
85+
expect(mapRemoteEnvironmentError(error, "relay").message).toBe(
86+
"The environment credential is invalid.",
87+
);
88+
expect(mapRemoteDpopEnvironmentError(error).message).toBe(
89+
`The environment credential is invalid. ${DPOP_UNKNOWN_HINT}`,
90+
);
91+
});
92+
93+
it.each([
94+
new RemoteEnvironmentAuthFetchError({
95+
message: "Failed to fetch remote environment endpoint.",
96+
cause: new TypeError("Failed to fetch"),
97+
}),
98+
new RemoteEnvironmentAuthTimeoutError("https://environment.example.test", 10_000),
99+
])("suggests another network when the relay endpoint cannot be reached: $_tag", (error) => {
100+
const mapped = mapRemoteDpopEnvironmentError(error);
101+
expect(mapped).toMatchObject({
102+
_tag: "ConnectionTransientError",
103+
detail: `${error.message} ${NETWORK_BLOCKING_HINT}`,
104+
});
105+
});
106+
51107
it("does not present a generic environment auth error as confirmed clock skew", () => {
52108
const mapped = mapRemoteDpopEnvironmentError(
53109
new EnvironmentAuthInvalidError({
Collapse file

‎packages/client-runtime/src/connection/errors.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/connection/errors.ts
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import type { EnvironmentId } from "@t3tools/contracts";
1+
import type { ClientConnectionMethod, EnvironmentId } from "@t3tools/contracts";
22
import type { RelayProtectedError } from "@t3tools/contracts/relay";
33
import type { ManagedRelayClientError } from "../relay/managedRelay.ts";
44
import { dpopFailureMessage, relayProtectedErrorMessage } from "../relay/errorPresentation.ts";
55
import type { RemoteEnvironmentAuthError } from "../authorization/remote.ts";
6+
import { NETWORK_BLOCKING_HINT } from "../errors/network.ts";
67
import {
78
ConnectionBlockedError,
89
type ConnectionAttemptError,
@@ -113,7 +114,9 @@ export function mapManagedRelayError(error: ManagedRelayClientError): Connection
113114

114115
export function mapRemoteEnvironmentError(
115116
error: RemoteEnvironmentAuthError,
117+
connectionMethod: ClientConnectionMethod = "direct",
116118
): ConnectionAttemptError {
119+
const networkHint = connectionMethod === "relay" ? ` ${NETWORK_BLOCKING_HINT}` : "";
117120
switch (error._tag) {
118121
case "EnvironmentAuthInvalidError":
119122
return new ConnectionBlockedError({
@@ -146,12 +149,12 @@ export function mapRemoteEnvironmentError(
146149
case "RemoteEnvironmentAuthTimeoutError":
147150
return new ConnectionTransientError({
148151
reason: "timeout",
149-
detail: error.message,
152+
detail: `${error.message}${networkHint}`,
150153
});
151154
case "RemoteEnvironmentAuthFetchError":
152155
return new ConnectionTransientError({
153156
reason: "network",
154-
detail: error.message,
157+
detail: `${error.message}${networkHint}`,
155158
});
156159
case "EnvironmentInternalError":
157160
return new ConnectionTransientError({
@@ -185,5 +188,5 @@ export function mapRemoteDpopEnvironmentError(
185188
traceId: error.traceId,
186189
});
187190
}
188-
return mapRemoteEnvironmentError(error);
191+
return mapRemoteEnvironmentError(error, "relay");
189192
}
Collapse file

‎packages/client-runtime/src/connection/supervisor.test.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/connection/supervisor.test.ts
+31-1Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
import * as RpcSession from "../rpc/session.ts";
3131
import * as EnvironmentSupervisor from "./supervisor.ts";
3232
import * as ConnectionWakeups from "./wakeups.ts";
33+
import { NETWORK_BLOCKING_HINT } from "../errors/network.ts";
3334

3435
const TARGET = new PrimaryConnectionTarget({
3536
environmentId: EnvironmentId.make("environment-1"),
@@ -467,6 +468,35 @@ describe("EnvironmentSupervisor", () => {
467468
}).pipe(Effect.provide(TestClock.layer())),
468469
);
469470

471+
it.effect(
472+
"shows a network hint for a stalled relay connection and clears it after recovery",
473+
() =>
474+
Effect.gen(function* () {
475+
const harness = yield* makeHarness({
476+
prepare: (attempt) =>
477+
attempt === 1 ? Effect.never : Effect.succeed(PREPARED_CONNECTION),
478+
});
479+
const supervisor = yield* EnvironmentSupervisor.make(RELAY_ENTRY, {
480+
initiallyDesired: true,
481+
}).pipe(Effect.provide(harness.dependencies));
482+
483+
yield* awaitState(supervisor.state, (state) => state.phase === "connecting");
484+
yield* TestClock.adjust("15 seconds");
485+
const failed = yield* awaitState(supervisor.state, (state) => state.phase === "backoff");
486+
expect(failed.lastFailure?.message).toBe(
487+
`Test environment did not respond during connection setup. ${NETWORK_BLOCKING_HINT}`,
488+
);
489+
490+
yield* TestClock.adjust("3 seconds");
491+
const recovered = yield* awaitState(
492+
supervisor.state,
493+
(state) => state.phase === "connected",
494+
);
495+
expect(recovered.lastFailure).toBeNull();
496+
expect(yield* Ref.get(harness.prepareCount)).toBe(2);
497+
}).pipe(Effect.provide(TestClock.layer())),
498+
);
499+
470500
it.effect("converts unexpected driver defects into retryable failures", () =>
471501
Effect.gen(function* () {
472502
const harness = yield* makeHarness({
@@ -475,7 +505,7 @@ describe("EnvironmentSupervisor", () => {
475505
? Effect.die(new Error("Native transport defect."))
476506
: Effect.succeed(PREPARED_CONNECTION),
477507
});
478-
const supervisor = yield* EnvironmentSupervisor.make(TARGET_ENTRY, {
508+
const supervisor = yield* EnvironmentSupervisor.make(RELAY_ENTRY, {
479509
initiallyDesired: true,
480510
}).pipe(Effect.provide(harness.dependencies));
481511

Collapse file

‎packages/client-runtime/src/connection/supervisor.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/connection/supervisor.ts
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
} from "./model.ts";
2929
import * as RpcSession from "../rpc/session.ts";
3030
import { safeErrorLogAttributes } from "../errors/safeLog.ts";
31+
import { NETWORK_BLOCKING_HINT } from "../errors/network.ts";
3132
import * as ConnectionWakeups from "./wakeups.ts";
3233

3334
const RETRY_DELAYS_MS = [3_000, 4_000, 8_000, 16_000] as const;
@@ -241,6 +242,9 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* (
241242
| ConnectionWakeups.ConnectionWakeups
242243
> {
243244
const target = entry.target;
245+
const setupTimeoutDetail = `${target.label} did not respond during connection setup.${
246+
target._tag === "RelayConnectionTarget" ? ` ${NETWORK_BLOCKING_HINT}` : ""
247+
}`;
244248
yield* annotateTarget(target);
245249

246250
const connectivity = yield* Connectivity.Connectivity;
@@ -626,7 +630,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* (
626630
} else {
627631
replacementError = new ConnectionTransientError({
628632
reason: "timeout",
629-
detail: `${target.label} did not respond during connection setup.`,
633+
detail: setupTimeoutDetail,
630634
});
631635
}
632636

@@ -708,7 +712,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* (
708712
failure: {
709713
error: new ConnectionTransientError({
710714
reason: "timeout",
711-
detail: `${target.label} did not respond during connection setup.`,
715+
detail: setupTimeoutDetail,
712716
}),
713717
attemptSpan: Option.none(),
714718
},
Collapse file

‎packages/client-runtime/src/errors/network.ts‎

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// A failed request cannot distinguish filtering from an outage. Keep this a
2+
// possible cause, and suggest a way to check without changing server settings.
3+
export const NETWORK_BLOCKING_HINT =
4+
"Your DNS or firewall may be blocking T3 Connect. Try another network, such as a phone hotspot.";
Collapse file

‎packages/client-runtime/src/relay/discovery.test.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/relay/discovery.test.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as Connectivity from "../connection/connectivity.ts";
1919
import { ConnectionBlockedError, type NetworkStatus } from "../connection/model.ts";
2020
import * as ConnectionWakeups from "../connection/wakeups.ts";
2121
import * as RelayEnvironmentDiscovery from "./discovery.ts";
22+
import { NETWORK_BLOCKING_HINT } from "../errors/network.ts";
2223

2324
const environments = [
2425
{
@@ -305,7 +306,7 @@ describe("RelayEnvironmentDiscovery", () => {
305306
expect(Option.getOrThrow(state.error)).toMatchObject({
306307
_tag: "ConnectionTransientError",
307308
reason: "timeout",
308-
message: "Relay environment listing timed out.",
309+
message: `Relay environment listing timed out. ${NETWORK_BLOCKING_HINT}`,
309310
});
310311
}).pipe(Effect.provide(layer));
311312
}),
Collapse file

‎packages/client-runtime/src/relay/managedRelay.test.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/relay/managedRelay.test.ts
+39-1Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ import * as Effect from "effect/Effect";
99
import * as Fiber from "effect/Fiber";
1010
import * as Layer from "effect/Layer";
1111
import * as Tracer from "effect/Tracer";
12+
import * as Schema from "effect/Schema";
1213
import * as TestClock from "effect/testing/TestClock";
1314

1415
import * as ManagedRelay from "./managedRelay.ts";
1516
import { remoteHttpClientLayer } from "../rpc/http.ts";
17+
import { NETWORK_BLOCKING_HINT } from "../errors/network.ts";
18+
19+
const encodeRelayError = Schema.encodeEffect(ManagedRelay.ManagedRelayClientError);
20+
const decodeRelayError = Schema.decodeUnknownEffect(ManagedRelay.ManagedRelayClientError);
1621

1722
function managedRelayTestLayer(
1823
fetchFn: typeof globalThis.fetch,
@@ -529,11 +534,44 @@ describe("ManagedRelayClient", () => {
529534
_tag: "ManagedRelayRequestTimeoutError",
530535
activity: "Relay environment listing",
531536
timeoutMs: ManagedRelay.MANAGED_RELAY_REQUEST_TIMEOUT_MS,
532-
message: "Relay environment listing timed out.",
537+
message: `Relay environment listing timed out. ${NETWORK_BLOCKING_HINT}`,
533538
});
534539
}).pipe(Effect.provide(Layer.merge(TestClock.layer(), managedRelayTestLayer(fetchFn))));
535540
});
536541

542+
it.effect("suggests checking network filtering when fetch fails without a response", () => {
543+
const fetchFn = (() =>
544+
Promise.reject(new TypeError("Failed to fetch"))) satisfies typeof globalThis.fetch;
545+
return Effect.gen(function* () {
546+
const relayClient = yield* ManagedRelay.ManagedRelayClient;
547+
const error = yield* relayClient
548+
.listEnvironments({ clerkToken: "clerk-token" })
549+
.pipe(Effect.flip);
550+
expect(error).toMatchObject({
551+
_tag: "ManagedRelayRequestFailedError",
552+
transportFailed: true,
553+
message: `Could not list relay-managed environments. ${NETWORK_BLOCKING_HINT}`,
554+
});
555+
const encoded = yield* encodeRelayError(error);
556+
const decoded = yield* decodeRelayError(encoded);
557+
expect(decoded.message).toBe(error.message);
558+
}).pipe(Effect.provide(managedRelayTestLayer(fetchFn)));
559+
});
560+
561+
it.effect("does not suggest network filtering for an HTTP server error", () => {
562+
const fetchFn = (() =>
563+
Promise.resolve(
564+
new Response("Unavailable", { status: 503 }),
565+
)) satisfies typeof globalThis.fetch;
566+
return Effect.gen(function* () {
567+
const relayClient = yield* ManagedRelay.ManagedRelayClient;
568+
const error = yield* relayClient
569+
.listEnvironments({ clerkToken: "clerk-token" })
570+
.pipe(Effect.flip);
571+
expect(error.message).toBe("Could not list relay-managed environments.");
572+
}).pipe(Effect.provide(managedRelayTestLayer(fetchFn)));
573+
});
574+
537575
it.effect("preserves typed relay trace IDs on client errors", () => {
538576
const fetchFn = (() =>
539577
Promise.resolve(
Collapse file

‎packages/client-runtime/src/relay/managedRelay.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/relay/managedRelay.ts
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import * as SynchronizedRef from "effect/SynchronizedRef";
4444
import * as HttpClientError from "effect/unstable/http/HttpClientError";
4545
import type * as HttpMethod from "effect/unstable/http/HttpMethod";
4646
import * as HttpApiClient from "effect/unstable/httpapi/HttpApiClient";
47+
import { NETWORK_BLOCKING_HINT } from "../errors/network.ts";
4748

4849
export interface ManagedRelayDpopProofInput {
4950
readonly method: HttpMethod.HttpMethod;
@@ -126,7 +127,7 @@ export class ManagedRelayRequestTimeoutError extends Schema.TaggedErrorClass<Man
126127
},
127128
) {
128129
override get message(): string {
129-
return `${this.activity} timed out.`;
130+
return `${this.activity} timed out. ${NETWORK_BLOCKING_HINT}`;
130131
}
131132
}
132133

@@ -145,13 +146,15 @@ export class ManagedRelayRequestFailedError extends Schema.TaggedErrorClass<Mana
145146
"ManagedRelayRequestFailedError",
146147
{
147148
action: ManagedRelayRequestAction,
149+
transportFailed: Schema.optionalKey(Schema.Boolean),
148150
cause: Schema.Defect(),
149151
relayError: Schema.optional(RelayProtectedError),
150152
traceId: Schema.optional(Schema.String),
151153
},
152154
) {
153155
override get message(): string {
154-
return `Could not ${this.action}.`;
156+
const message = `Could not ${this.action}.`;
157+
return this.transportFailed ? `${message} ${NETWORK_BLOCKING_HINT}` : message;
155158
}
156159
}
157160

@@ -307,6 +310,8 @@ function relayRequestError(action: ManagedRelayRequestAction) {
307310
return (cause: RelayHttpRequestError): ManagedRelayClientError =>
308311
new ManagedRelayRequestFailedError({
309312
action,
313+
transportFailed:
314+
HttpClientError.isHttpClientError(cause) && cause.reason._tag === "TransportError",
310315
cause,
311316
...(isRelayProtectedError(cause) ? { relayError: cause, traceId: cause.traceId } : {}),
312317
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.