Skip to content

Commit 62539aa

Browse files
t3dotggclaude
andcommitted
fix(connect): recheck reachability every 5 minutes and keep 502 over edge failures
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 15c86d2 commit 62539aa

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎apps/server/src/cloud/ConnectReachability.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ describe("classifyReachability", () => {
7171
checkedAt,
7272
),
7373
).toMatchObject({ cause: "origin_unreachable" });
74+
expect(
75+
classifyReachability(
76+
facts({
77+
connector: { readyConnections: null, hostname: "env.example.test", protocol: null },
78+
endpoint: { kind: "status", status: 502 },
79+
edgeReachable: false,
80+
}),
81+
checkedAt,
82+
),
83+
).toMatchObject({ cause: "origin_unreachable" });
7484
// Failed DNS also fails the edge lookups.
7585
expect(
7686
classifyReachability(

‎apps/server/src/cloud/ConnectReachability.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const EDGE_CONNECT_TIMEOUT = Duration.seconds(5);
2525
const ENDPOINT_REQUEST_TIMEOUT = Duration.seconds(10);
2626
// cloudflared registers several connections within a few seconds; they are one change.
2727
const READINESS_CHANGE_DEBOUNCE = Duration.seconds(3);
28+
// Readiness changes miss failures and recoveries past cloudflared (DNS, origin, edge errors).
29+
const RECHECK_INTERVAL = Duration.minutes(5);
2830

2931
export type EndpointProbe =
3032
| { readonly kind: "status"; readonly status: number }
@@ -84,10 +86,11 @@ export function classifyReachability(
8486
protocol: connector.protocol,
8587
};
8688
}
87-
// The edge test is TCP only. With QUIC connections up, or with DNS already failing, a
88-
// failed TCP test would hide the real cause.
89+
// The edge test is TCP only. With QUIC connections up, a 502 from a working tunnel, or
90+
// DNS already failing, a failed TCP test would hide the real cause.
8991
if (
9092
facts.edgeReachable === false &&
93+
status !== 502 &&
9194
!(connector.readyConnections && connector.readyConnections > 0) &&
9295
endpoint?.kind !== "dns_failed"
9396
) {
@@ -279,6 +282,11 @@ const make = Effect.gen(function* () {
279282
Stream.runForEach(() => check),
280283
Effect.forkScoped,
281284
);
285+
yield* Effect.sleep(RECHECK_INTERVAL).pipe(
286+
Effect.andThen(check),
287+
Effect.forever,
288+
Effect.forkScoped,
289+
);
282290

283291
return ConnectReachability.of({ check, latest: Ref.get(latestRef) });
284292
});

0 commit comments

Comments
 (0)