Skip to content

Commit 48c0154

Browse files
committed
fix(connect): keep origin backoff on unreadable ingress and forward recovery_required
The origin watcher reset its backoff whenever the connector config could not be read, logged the raw ingress URL, and dropped a recovery_required registration instead of requesting tunnel recovery like the other registration callers.
1 parent b62a17c commit 48c0154

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,14 @@ describe("watchManagedTunnelOrigin", () => {
103103
expect(result.registeredAtMinute).toEqual([1, 3, 7, 15]);
104104
}),
105105
);
106+
107+
it.effect("keeps the backoff when one check cannot read the ingress", () =>
108+
Effect.gen(function* () {
109+
const result = yield* watch({
110+
ingress: ["http://127.0.0.1:46169", null, "http://127.0.0.1:46169"],
111+
minutes: 10,
112+
});
113+
expect(result.registeredAtMinute).toEqual([1, 5, 9]);
114+
}),
115+
);
106116
});

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ export const makeManagedTunnelRecovery = Effect.fn("ManagedTunnelRecovery.make")
220220

221221
const MANAGED_TUNNEL_ORIGIN_CHECK_INTERVAL = Duration.minutes(1);
222222

223-
const sameOrigin = (left: string, right: string) => {
223+
const urlOrigin = (url: string) => {
224224
try {
225-
return new URL(left).origin === new URL(right).origin;
225+
return new URL(url).origin;
226226
} catch {
227-
return false;
227+
return null;
228228
}
229229
};
230230

@@ -247,17 +247,21 @@ export const watchManagedTunnelOrigin = Effect.fn("ManagedTunnelOrigin.watch")(f
247247
readonly readIngressOrigin: Effect.Effect<string | null>;
248248
readonly register: Effect.Effect<unknown, E, R>;
249249
}) {
250+
const localOrigin = urlOrigin(options.localOrigin);
250251
let wait = MANAGED_TUNNEL_ORIGIN_CHECK_INTERVAL;
251252
while (true) {
252253
yield* Effect.sleep(wait);
253-
const ingressOrigin = yield* options.readIngressOrigin;
254-
if (ingressOrigin === null || sameOrigin(ingressOrigin, options.localOrigin)) {
254+
const ingress = yield* options.readIngressOrigin;
255+
// An unreadable ingress says nothing, so it keeps whatever backoff is running.
256+
if (ingress === null) continue;
257+
const ingressOrigin = urlOrigin(ingress);
258+
if (ingressOrigin !== null && ingressOrigin === localOrigin) {
255259
wait = MANAGED_TUNNEL_ORIGIN_CHECK_INTERVAL;
256260
continue;
257261
}
258262
yield* Effect.logWarning(
259263
"T3 Connect routes this server's tunnel to another origin; registering this server again",
260-
{ ingressOrigin, localOrigin: options.localOrigin },
264+
{ ingressOrigin: ingressOrigin ?? "unparseable", localOrigin },
261265
);
262266
yield* options.register.pipe(
263267
Effect.catchCause((cause) =>

‎apps/server/src/server.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,15 @@ const layerMakeServer = Layer.unwrap(
899899
readIngressOrigin: endpointRuntime.inspectConnector.pipe(
900900
Effect.map((connector) => connector?.origin ?? null),
901901
),
902-
register: cloudLink.registerManagedTunnelRecovery(localOrigin),
902+
register: cloudLink
903+
.registerManagedTunnelRecovery(localOrigin)
904+
.pipe(
905+
Effect.flatMap((registration) =>
906+
registration.status === "recovery_required"
907+
? endpointRuntime.requestRecovery(registration.config)
908+
: Effect.void,
909+
),
910+
),
903911
}).pipe(Effect.forkScoped);
904912
const wantsCliLink = hasCloudPublicConfig
905913
? yield* CloudCliState.readCliDesiredCloudLink.pipe(

0 commit comments

Comments
 (0)