Skip to content
TypeScript

fix(client-runtime): Update clears the block on a host that is already compatible (#18563)

Pujitha Paladugu10db5e493f24
diff --git a/packages/client-runtime/src/connection/outdatedHostUpdate.test.ts b/packages/client-runtime/src/connection/outdatedHostUpdate.test.ts
index 4bee35c8d85..38004a0875f 100644
--- a/packages/client-runtime/src/connection/outdatedHostUpdate.test.ts
+++ b/packages/client-runtime/src/connection/outdatedHostUpdate.test.ts
@@ -204,6 +204,84 @@ describe("updateOutdatedHost", () => {
}),
);
+ it.effect("switches a host that is already compatible back on without opening a socket", () =>
+ Effect.gen(function* () {
+ const calls: Array<string> = [];
+ let opened = false;
+ const prepared = {
+ environmentId: TARGET.environmentId,
+ label: TARGET.label,
+ httpBaseUrl: TARGET.httpBaseUrl,
+ socketUrl: "wss://build.example.test/ws",
+ httpAuthorization: null,
+ target: TARGET,
+ };
+ const result = yield* updateOutdatedHost(
+ TARGET.environmentId,
+ { targetVersion: "0.0.46" },
+ () => Effect.void,
+ ).pipe(
+ Effect.provide(
+ Layer.mergeAll(
+ Layer.succeed(
+ EnvironmentRegistry.EnvironmentRegistry,
+ EnvironmentRegistry.EnvironmentRegistry.of({
+ entries: yield* SubscriptionRef.make<
+ ReadonlyMap<EnvironmentId, ConnectionCatalogEntry>
+ >(
+ new Map([
+ [
+ TARGET.environmentId,
+ { target: TARGET, profile: Option.none(), enabled: false },
+ ],
+ ]),
+ ),
+ setCompatibility: (_environmentId: EnvironmentId, error: unknown) =>
+ Effect.sync(() =>
+ calls.push(`compatibility:${error === null ? "clear" : "block"}`),
+ ),
+ setEnabled: (_environmentId: EnvironmentId, enabled: boolean) =>
+ Effect.sync(() => calls.push(`enabled:${enabled}`)),
+ } as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]),
+ ),
+ Layer.succeed(
+ ConnectionResolver.ConnectionResolver,
+ ConnectionResolver.ConnectionResolver.of({
+ prepare: () => Effect.die(new Error("unused")),
+ prepareForUpdate: () =>
+ Effect.succeed({
+ descriptor: descriptor(ORCHESTRATION_PROTOCOL_VERSION, "0.0.46"),
+ prepared,
+ }),
+ }),
+ ),
+ Layer.succeed(
+ RelayEnvironmentDiscovery.RelayEnvironmentDiscovery,
+ RelayEnvironmentDiscovery.RelayEnvironmentDiscovery.of({
+ state: yield* SubscriptionRef.make(
+ RelayEnvironmentDiscovery.EMPTY_RELAY_ENVIRONMENT_DISCOVERY_STATE,
+ ),
+ refresh: Effect.void,
+ }),
+ ),
+ Layer.succeed(
+ HttpClient.HttpClient,
+ HttpClient.make(() => Effect.die(new Error("unused"))),
+ ),
+ // A v2 host answers a bare socket with 426, so opening one fails.
+ Layer.succeed(Socket.WebSocketConstructor, () => {
+ opened = true;
+ throw new Error("unused");
+ }),
+ ),
+ ),
+ );
+ expect(opened).toBe(false);
+ expect(result.targetVersion).toBe("0.0.46");
+ expect(calls).toEqual(["compatibility:clear", "enabled:true"]);
+ }),
+ );
+
it.effect("refuses a host that cannot update itself without opening a socket", () =>
Effect.gen(function* () {
const manual = {
diff --git a/packages/client-runtime/src/connection/outdatedHostUpdate.ts b/packages/client-runtime/src/connection/outdatedHostUpdate.ts
index e248fb03f19..e692eab7257 100644
--- a/packages/client-runtime/src/connection/outdatedHostUpdate.ts
+++ b/packages/client-runtime/src/connection/outdatedHostUpdate.ts
@@ -70,6 +70,24 @@ export const updateOutdatedHost = Effect.fn("clientRuntime.connection.updateOutd
const { prepared, descriptor } = yield* Effect.firstSuccessOf(
usableRoutes(entry).map((route) => resolver.prepareForUpdate(routeEntry(entry, route))),
);
+ // Discovery still holds the old relay descriptor and would re-block the
+ // environment from it, so replace that before clearing the block.
+ const switchBackOn = Effect.gen(function* () {
+ if (hasRelayRoute(entry)) {
+ const discovery = yield* RelayEnvironmentDiscovery.RelayEnvironmentDiscovery;
+ yield* discovery.refresh;
+ }
+ yield* registry.setCompatibility(environmentId, null);
+ yield* registry.setEnabled(environmentId, true);
+ });
+
+ // A host updated by hand is already compatible, and a bare socket would be
+ // rejected with 426, so there is nothing to update.
+ if (isCompatibleDescriptor(descriptor)) {
+ yield* switchBackOn;
+ return { targetVersion: descriptor.serverVersion };
+ }
+
const capabilities = descriptor.capabilities;
if (
capabilities.serverSelfUpdate === undefined ||
@@ -192,14 +210,7 @@ export const updateOutdatedHost = Effect.fn("clientRuntime.connection.updateOutd
});
}
- // Discovery still holds the old relay descriptor and would re-block the
- // environment from it, so replace that before clearing the block.
- if (hasRelayRoute(entry)) {
- const discovery = yield* RelayEnvironmentDiscovery.RelayEnvironmentDiscovery;
- yield* discovery.refresh;
- }
- yield* registry.setCompatibility(environmentId, null);
- yield* registry.setEnabled(environmentId, true);
+ yield* switchBackOn;
return { ...result, targetVersion: resumed.value.serverVersion };
},
);