Skip to content

Commit 3a110af

Browse files
committed
test(client-runtime): focus route stability regressions
1 parent 6c88073 commit 3a110af

3 files changed

Lines changed: 8 additions & 43 deletions

File tree

‎docs/internals/connection-runtime.md‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ client of a restarted server reconnects in the same second; with a short cap, a
1616
client that can never connect retries all day. Offline states and authentication
1717
failures wait for a wakeup instead of spending attempts on unchanged conditions.
1818

19-
Route ranking applies when establishing a connection, including routes learned
20-
from the current session. A better route answering discovery does not prove its
21-
socket will work, so it never replaces a healthy session. The next necessary
22-
connection uses the latest routes; there is no second session to synchronize or
23-
handoff while the current one is healthy.
19+
A healthy session stays on its current route: discovery does not prove that a
20+
better route can establish a socket. Necessary reconnects use the latest ranked
21+
routes, including those learned from the current session.
2422

2523
Foregrounding, an explicit retry, and an offline report probe the established
2624
session, and only a failed probe reconnects. Offline reports are often wrong, for

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ export type RouteCheck = "answered" | "silent" | "unchecked";
3636

3737
const ROUTE_CHECK_TIMEOUT_MS = 2_500;
3838
// Preferred direct routes share one head start, so a relay connection does not
39-
// wait the full probe timeout for a LAN the device has already left. A route
40-
// that misses it can be selected on the next connection attempt.
39+
// wait the full probe timeout for a LAN the device has already left.
4140
const ROUTE_CHECK_HEAD_START_MS = 500;
4241

4342
export class ConnectionDriver extends Context.Service<

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

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,12 +1049,8 @@ describe("EnvironmentSupervisor routes", () => {
10491049
},
10501050
]);
10511051
const harness = yield* makeHarness();
1052-
const allowLan = yield* Ref.make(false);
10531052
const opened = yield* Ref.make<ReadonlyArray<string>>([]);
10541053
const released = yield* Ref.make<ReadonlyArray<string>>([]);
1055-
const closures = yield* Ref.make<
1056-
ReadonlyArray<Deferred.Deferred<never, ConnectionTransientError>>
1057-
>([]);
10581054
const driver = yield* ConnectionDriver.make.pipe(
10591055
Effect.provideService(ConnectionResolver.ConnectionResolver, {
10601056
prepare: (route) => Effect.succeed(preparedFor(route.target)),
@@ -1065,18 +1061,16 @@ describe("EnvironmentSupervisor routes", () => {
10651061
Effect.gen(function* () {
10661062
const id = connectionRouteId(prepared.target);
10671063
yield* Ref.update(opened, (ids) => [...ids, id]);
1068-
const fails = id === LAN_TARGET.connectionId && !(yield* Ref.get(allowLan));
1064+
const fails = id === LAN_TARGET.connectionId;
10691065
if (fails && failureStage === "opening") return yield* transient();
1070-
const closed = yield* Deferred.make<never, ConnectionTransientError>();
1071-
yield* Ref.update(closures, (all) => [...all, closed]);
10721066
return yield* Effect.acquireRelease(
10731067
Effect.succeed({
10741068
client: TEST_RPC_CLIENT,
10751069
initialConfig: Effect.die("unused"),
10761070
subscribeServerConfig: () => Stream.die("unused"),
10771071
ready: fails ? Effect.fail(transient()) : Effect.void,
10781072
probe: Effect.void,
1079-
closed: Deferred.await(closed),
1073+
closed: Effect.never,
10801074
} satisfies RpcSession.RpcSession),
10811075
() => Ref.update(released, (ids) => [...ids, id]),
10821076
);
@@ -1123,40 +1117,14 @@ describe("EnvironmentSupervisor routes", () => {
11231117
generation: 1,
11241118
});
11251119

1126-
// An actual lifecycle replacement still tries LAN and falls back if setup fails.
1127-
yield* harness.wake("application-active-reconnect");
1128-
yield* awaitState(
1129-
supervisor.state,
1130-
(state) => state.phase === "connected" && state.generation === 2,
1131-
);
1132-
expect(Option.getOrThrow(yield* SubscriptionRef.get(supervisor.prepared)).target).toEqual(
1133-
tailnetTarget,
1134-
);
1135-
expect(yield* Ref.get(opened)).toEqual([...baseline, ...baseline]);
1136-
yield* Ref.set(allowLan, true);
1137-
yield* Deferred.fail((yield* Ref.get(closures)).at(-1)!, transient());
1138-
yield* awaitState(supervisor.state, (state) => state.phase === "backoff");
1139-
yield* TestClock.adjust("3 seconds");
1140-
yield* awaitState(
1141-
supervisor.state,
1142-
(state) => state.phase === "connected" && state.generation === 3,
1143-
);
1144-
expect(Option.getOrThrow(yield* SubscriptionRef.get(supervisor.prepared)).target).toEqual(
1145-
LAN_TARGET,
1146-
);
1147-
expect(yield* Ref.get(opened)).toEqual([...baseline, ...baseline, LAN_TARGET.connectionId]);
1148-
if (failureStage === "opening") {
1149-
yield* supervisor.disconnect;
1150-
yield* awaitState(supervisor.state, (state) => state.phase === "available");
1151-
}
11521120
yield* Scope.close(scope, Exit.void);
11531121
expect(Option.isNone(yield* SubscriptionRef.get(supervisor.session))).toBe(true);
11541122
expect(
11551123
(yield* Ref.get(released)).filter((id) => id === tailnetTarget.connectionId),
1156-
).toHaveLength(2);
1124+
).toHaveLength(1);
11571125
expect(
11581126
(yield* Ref.get(released)).filter((id) => id === LAN_TARGET.connectionId),
1159-
).toHaveLength(failureStage === "opening" ? 1 : 3);
1127+
).toHaveLength(failureStage === "opening" ? 0 : 1);
11601128
}).pipe(Effect.provide(TestClock.layer())),
11611129
);
11621130

0 commit comments

Comments
 (0)