Skip to content

Commit 9918373

Browse files
committed
refactor(relay): shorten reconnect cleanup rationale
1 parent cfc68d7 commit 9918373

3 files changed

Lines changed: 4 additions & 21 deletions

File tree

‎infra/relay/src/environments/EnvironmentLinks.test.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ describe("EnvironmentLinks", () => {
4747
);
4848
});
4949

50-
// The reaper can list an allocation while its recovery key differs from the
51-
// link and release it later at that generation. A link that restores the key
52-
// must move the generation before it commits, or the release deletes the
53-
// tunnel the relink just provisioned. The link write comes first, matching
54-
// enableRecovery's link-then-allocation lock order so the two cannot deadlock.
5550
it.effect("moves the allocation generation when a link restores its recovery key", () => {
5651
const events: Array<string> = [];
5752
const allocationUpdates: Array<{

‎infra/relay/src/environments/EnvironmentLinks.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,8 @@ const make = Effect.gen(function* () {
194194
...(request.deviceId === undefined ? {} : { deviceId: request.deviceId }),
195195
cause,
196196
});
197-
// The reaper may have listed this allocation while its recovery key did
198-
// not match the link, and then releases it without the recent
199-
// registration guard. A link proven by that key makes recovery usable
200-
// again, so it moves the generation the release was pinned to. Both
201-
// writes commit together, and the bump waits on the allocation row lock
202-
// a claimed release holds while it deletes the tunnel. The link is
203-
// written first to keep enableRecovery's order: its EXISTS locks the
204-
// link row before its UPDATE locks the allocation row.
197+
// Restoring the recovery key invalidates a stale reaper claim atomically.
198+
// Lock the link before the allocation, matching enableRecovery.
205199
const writeLink = Effect.gen(function* () {
206200
yield* db
207201
.insert(relayEnvironmentLinks)

‎infra/relay/src/environments/ManagedEndpointProvider.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -983,20 +983,14 @@ export const make = Effect.gen(function* () {
983983
if (input.expectedTunnelId !== undefined && input.expectedTunnelId !== tunnelId) {
984984
return false;
985985
}
986-
// The caller judged the allocation as it was when listed. A write since
987-
// then, such as a recovery registration, may have made its tunnel
988-
// recoverable again, so the next sweep decides with fresh data.
986+
// Recovery may become usable after the reaper lists the allocation.
989987
if (
990988
input.expectedGeneration !== undefined &&
991989
input.expectedGeneration !== allocation.generation
992990
) {
993991
return false;
994992
}
995-
// A starting host registers recovery while cloudflared is still
996-
// connecting, so Cloudflare keeps reporting the tunnel's old inactivity.
997-
// A registration after the cutoff means the host is coming back to it.
998-
// A relink that replaced the environment key keeps the old timestamp,
999-
// but that registration can no longer recover the tunnel.
993+
// Cloudflare reports old inactivity while a registered host is reconnecting.
1000994
if (
1001995
input.expectedInactiveBefore !== undefined &&
1002996
input.expectedRecoveryEnabled !== false &&

0 commit comments

Comments
 (0)