Skip to content

Commit 319dafc

Browse files
fix(server): an interrupted relay client activation still supervises the client
The uninterruptible handover set activeRef but forked the connector's watchers after it, so an interrupt delivered at the end of the handover left an unsupervised connector whose output was never drained. Fork the watchers inside the handover, each restored to interruptible. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 505f066 commit 319dafc

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,13 @@ describe("CloudManagedEndpointRuntime", () => {
464464
yield* Deferred.succeed(recorded, undefined);
465465
yield* Fiber.join(interrupting);
466466

467+
// The handed-over connector is supervised: its exit starts a replacement.
468+
expect(yield* Queue.take(fixture.started)).toBe(0);
469+
yield* Deferred.succeed(fixture.exits[0]!, ChildProcessSpawner.ExitCode(1));
470+
expect(yield* Queue.take(fixture.started)).toBe(1);
471+
467472
yield* runtime.applyConfig(null);
468-
expect(fixture.killed).toEqual([800]);
473+
expect(fixture.killed).toEqual([800, 801]);
469474
}).pipe(
470475
Effect.provideService(HostProcess.Environment, {}),
471476
Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} }))),

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,8 @@ export const make = Effect.gen(function* () {
827827
}
828828

829829
if (!("status" in child)) {
830-
// An interrupt before activeRef owns the connector would leave its scope, and the client, open.
831-
const connector = yield* Effect.uninterruptible(
830+
// An interrupt before activeRef owns a supervised connector would leave its client open or unwatched.
831+
yield* Effect.uninterruptibleMask((restore) =>
832832
Effect.gen(function* () {
833833
forgetRelayClient = yield* relayClientLedger.track(Number(child.pid));
834834
const connector = {
@@ -843,13 +843,12 @@ export const make = Effect.gen(function* () {
843843
protocol: yield* Ref.make<string | null>(null),
844844
} satisfies ActiveConnector;
845845
yield* Ref.set(activeRef, connector);
846-
return connector;
846+
yield* Effect.forkIn(restore(observeConnectorOutput(connector)), connectorScope);
847+
yield* Effect.forkIn(restore(superviseConnector(connector)), connectorScope);
848+
yield* Effect.forkIn(restore(watchConnectorRegistration(connector)), connectorScope);
849+
yield* Effect.forkIn(restore(watchConnectorReadiness(connector)), connectorScope);
847850
}),
848851
);
849-
yield* Effect.forkIn(observeConnectorOutput(connector), connectorScope);
850-
yield* Effect.forkIn(superviseConnector(connector), connectorScope);
851-
yield* Effect.forkIn(watchConnectorRegistration(connector), connectorScope);
852-
yield* Effect.forkIn(watchConnectorReadiness(connector), connectorScope);
853852
return {
854853
status: "running",
855854
providerKind: "cloudflare_tunnel",

0 commit comments

Comments
 (0)