Skip to content

Commit 7b15585

Browse files
author
PR Batch Tester
committed
fix(connect): discard replaced connector facts and respect relay state
1 parent 4fff01a commit 7b15585

4 files changed

Lines changed: 54 additions & 8 deletions

File tree

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as Sink from "effect/Sink";
1212
import * as Stream from "effect/Stream";
1313
import * as TestClock from "effect/testing/TestClock";
1414
import { ChildProcess, ChildProcessSpawner } from "effect/process";
15-
import { HttpClient } from "effect/http";
15+
import { HttpClient, HttpClientResponse } from "effect/http";
1616
import type { RelayManagedEndpointRuntimeConfig } from "@t3tools/contracts/relay";
1717
import * as RelayClient from "@t3tools/shared/relayClient";
1818

@@ -288,6 +288,46 @@ describe("CloudManagedEndpointRuntime", () => {
288288
return { spawner, spawned, killed, exits, started, emit, observe };
289289
});
290290

291+
it.effect("discards metrics from a connector replaced with the same configuration", () =>
292+
Effect.gen(function* () {
293+
const readingConfig = yield* Deferred.make<void>();
294+
const releaseConfig = yield* Deferred.make<void>();
295+
const fixture = yield* makeTransportSpawner();
296+
const httpClient = HttpClient.make((request) =>
297+
Effect.gen(function* () {
298+
const isConfig = request.url.endsWith("/config");
299+
if (isConfig) {
300+
yield* Deferred.succeed(readingConfig, undefined);
301+
yield* Deferred.await(releaseConfig);
302+
}
303+
return HttpClientResponse.fromWeb(
304+
request,
305+
new Response(
306+
JSON.stringify(
307+
isConfig
308+
? { config: { ingress: [{ hostname: "old.example.test" }] } }
309+
: { readyConnections: 4 },
310+
),
311+
),
312+
);
313+
}),
314+
);
315+
const runtime = yield* buildCloudManagedEndpointRuntime(
316+
fixture.spawner,
317+
layerRelayClientAvailable,
318+
httpClient,
319+
);
320+
yield* runtime.applyConfig(tunnelConfig);
321+
yield* fixture.observe(runtime, 0, "Starting metrics server on 127.0.0.1:12345/metrics\n");
322+
const inspection = yield* runtime.inspectConnector(tunnelConfig).pipe(Effect.forkChild);
323+
yield* Deferred.await(readingConfig);
324+
yield* runtime.applyConfig(null);
325+
yield* runtime.applyConfig(tunnelConfig);
326+
yield* Deferred.succeed(releaseConfig, undefined);
327+
expect(yield* Fiber.join(inspection)).toBeNull();
328+
}),
329+
);
330+
291331
it.effect("preserves an explicit transport choice despite repeated QUIC stalls", () =>
292332
Effect.gen(function* () {
293333
const fixture = yield* makeTransportSpawner({ transport: "quic" });

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,12 @@ export const make = Effect.gen(function* () {
784784
],
785785
{ concurrency: 2 },
786786
);
787+
if (
788+
!(yield* active.child.isRunning.pipe(Effect.orElseSucceed(() => false))) ||
789+
(yield* Ref.get(activeRef)) !== active
790+
) {
791+
return null;
792+
}
787793
return {
788794
readyConnections: ready?.readyConnections ?? null,
789795
hostname: config?.config.ingress?.find((rule) => rule.hostname)?.hostname ?? null,

‎apps/web/src/components/settings/ConnectionsSettings.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ export function ConnectionsSettings() {
10701070
environmentId={primaryEnvironmentId}
10711071
serverConfig={primaryServerConfig}
10721072
/>
1073-
<PrimaryMcpUrlMenuItem />
1073+
{hasCloudPublicConfig() ? <PrimaryMcpUrlMenuItem /> : null}
10741074
</MenuPopup>
10751075
</Menu>
10761076
) : null

‎apps/web/src/components/settings/SavedEnvironmentRows.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ import {
4949
supportsServerUpdateThreadContinuation,
5050
} from "~/versionSkew";
5151
import { hasCloudPublicConfig } from "~/cloud/publicConfig";
52-
import {
53-
primaryCloudLinkMutationAtom,
54-
usePrimaryCloudLinkState,
55-
} from "~/cloud/primaryCloudLinkState";
52+
import { primaryCloudLinkMutationAtom } from "~/cloud/primaryCloudLinkState";
5653
import { useCloudLinkController, type CloudLinkDesiredState } from "~/cloud/useCloudLinkController";
5754
import { environmentCatalog } from "~/connection/catalog";
5855
import { readEnvironmentScope } from "~/state/session";
@@ -133,10 +130,13 @@ function useCopyMcpUrl() {
133130
}
134131

135132
export function PrimaryMcpUrlMenuItem() {
136-
const { data, isPending } = usePrimaryCloudLinkState();
133+
const {
134+
linkState: { data, isPending },
135+
managedTunnelActive,
136+
} = useCloudLinkController();
137137
const copyMcpUrl = useCopyMcpUrl();
138138
const reachability =
139-
data && !isPending && data.managedTunnelActive !== false && data.linkRevoked !== true
139+
data && !isPending && managedTunnelActive && data.linkRevoked !== true
140140
? data.reachability
141141
: undefined;
142142
const mcpUrl = reachability?.status === "reachable" ? connectReachableMcpUrl(reachability) : null;

0 commit comments

Comments
 (0)