Skip to content

Commit 0838054

Browse files
committed
fix(connection): preserve opened snapshots when the network path changes
1 parent 7f6ae20 commit 0838054

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,34 @@ describe("EnvironmentSupervisor", () => {
605605
}).pipe(Effect.provide(TestClock.layer())),
606606
);
607607

608+
it.effect("keeps an opened synchronization through a network-path wakeup", () =>
609+
Effect.gen(function* () {
610+
const synchronizing = yield* Deferred.make<void>();
611+
const finishSnapshot = yield* Deferred.make<void>();
612+
const harness = yield* makeHarness({
613+
ready: () =>
614+
Deferred.succeed(synchronizing, undefined).pipe(
615+
Effect.andThen(Deferred.await(finishSnapshot)),
616+
),
617+
});
618+
const supervisor = yield* EnvironmentSupervisor.make(RELAY_ENTRY, {
619+
initiallyDesired: true,
620+
}).pipe(Effect.provide(harness.dependencies));
621+
622+
yield* Deferred.await(synchronizing);
623+
yield* harness.wake("network-changed");
624+
yield* TestClock.adjust("0 millis");
625+
expect(yield* Ref.get(harness.sessionCount)).toBe(1);
626+
expect(yield* Ref.get(harness.releaseCount)).toBe(0);
627+
628+
yield* Deferred.succeed(finishSnapshot, undefined);
629+
yield* awaitState(supervisor.state, (state) => state.phase === "connected");
630+
expect(yield* Ref.get(harness.prepareCount)).toBe(1);
631+
expect(yield* Ref.get(harness.sessionCount)).toBe(1);
632+
expect(yield* Ref.get(harness.releaseCount)).toBe(0);
633+
}).pipe(Effect.provide(TestClock.layer())),
634+
);
635+
608636
const unansweredFirstProbe = (attempt: number) => (attempt === 1 ? Effect.never : Effect.void);
609637

610638
it.effect.each([

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* (
628628
return true;
629629
}
630630
// One started before a network change can hang until its setup timeout.
631-
if (next.reason === "network-changed") {
631+
if (next.reason === "network-changed" && !(yield* SubscriptionRef.get(routeOpen))) {
632632
return true;
633633
}
634634
if (next.reason === "credentials-changed" && usesRelay) {

0 commit comments

Comments
 (0)