Skip to content

Commit 8aee9bc

Browse files
fix(server): clear the cached SSH device endpoint when an interrupted start closes its forward
An interrupt while the ready status was being published closed the forward but kept `ready`, so the next ensureReady returned an endpoint with no tunnel behind it. Clear `ready` together with the scope. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8641a14 commit 8aee9bc

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎apps/server/src/device/SshDeviceHost.test.ts‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,21 @@ it.effect("releases the forward of a bootstrap interrupted before its hub answer
239239
});
240240
}),
241241
);
242-
const host = yield* SshDeviceHost.make({
243-
kind: "ssh",
244-
id: "test",
245-
label: "Test",
246-
target: "test.example",
247-
}).pipe(
242+
const publishing = yield* Deferred.make<void>();
243+
let holdReadyStatus = false;
244+
const host = yield* SshDeviceHost.make(
245+
{
246+
kind: "ssh",
247+
id: "test",
248+
label: "Test",
249+
target: "test.example",
250+
},
251+
undefined,
252+
(status) =>
253+
status === "ready" && holdReadyStatus
254+
? Deferred.succeed(publishing, undefined).pipe(Effect.andThen(Effect.never))
255+
: Effect.void,
256+
).pipe(
248257
Effect.provide(Layer.mergeAll(ServerConfig.layerTest(home, home), Net.layer)),
249258
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
250259
Effect.provideService(
@@ -268,6 +277,15 @@ it.effect("releases the forward of a bootstrap interrupted before its hub answer
268277
yield* host.ensureReady(() => Effect.void);
269278
yield* host.stop;
270279
expect(forwards).toBe(0);
280+
holdReadyStatus = true;
281+
const second = yield* host.ensureReady(() => Effect.void).pipe(Effect.forkChild);
282+
yield* Deferred.await(publishing);
283+
yield* Fiber.interrupt(second);
284+
holdReadyStatus = false;
285+
yield* host.ensureReady(() => Effect.void);
286+
expect(forwards).toBe(1);
287+
yield* host.stop;
288+
expect(forwards).toBe(0);
271289
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
272290
);
273291

‎apps/server/src/device/SshDeviceHost.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ export const make = Effect.fn("SshDeviceHost.make")(function* (
476476
const closeConnection = Effect.suspend(() => {
477477
const failedScope = connectionScope;
478478
connectionScope = null;
479+
ready = null;
479480
return failedScope ? Scope.close(failedScope, Exit.void) : Effect.void;
480481
});
481482

0 commit comments

Comments
 (0)