Skip to content

Commit 9086af2

Browse files
committed
fix(server): bound viewer screencast cleanup
1 parent d5bfee8 commit 9086af2

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎apps/server/src/preview/ServerBrowser.test.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,20 +2657,25 @@ it.effect("viewer cleanup detaches after a stalled stop command", () =>
26572657
Effect.gen(function* () {
26582658
const { browser, tabId } = yield* ready;
26592659
const viewerScope = yield* Scope.make();
2660-
yield* browser.attachViewer(viewerInput(tabId, true)).pipe(Effect.provideService(Scope.Scope, viewerScope));
2660+
yield* browser
2661+
.attachViewer(viewerInput(tabId, true))
2662+
.pipe(Effect.provideService(Scope.Scope, viewerScope));
26612663
const session = contexts[0]!.sessions.at(-1)!;
26622664
const stopped = yield* Queue.unbounded<void>();
2665+
const stalledStop = Promise.withResolvers<Record<string, unknown>>();
26632666
const answer = session.send.getMockImplementation()!;
26642667
session.send.mockImplementation(async (method: string, input?: unknown) => {
26652668
if (method !== "Page.stopScreencast") return answer(method, input);
26662669
Queue.offerUnsafe(stopped, undefined);
2667-
return new Promise<never>(() => {});
2670+
return stalledStop.promise;
26682671
});
26692672
const closing = yield* Scope.close(viewerScope, Exit.void).pipe(Effect.forkScoped);
26702673
yield* Queue.take(stopped);
26712674
yield* TestClock.adjust("5 seconds");
2675+
const detached = session.detach.mock.calls.length;
2676+
stalledStop.resolve({});
26722677
yield* Fiber.join(closing);
2673-
expect(session.detach).toHaveBeenCalled();
2678+
expect(detached).toBe(1);
26742679
}),
26752680
).pipe(Effect.provide(layer)),
26762681
);

‎apps/server/src/preview/ServerBrowser.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,9 +2578,7 @@ const make = Effect.gen(function* () {
25782578
}),
25792579
(session) =>
25802580
Effect.promise(() =>
2581-
session
2582-
.send("Page.stopScreencast")
2583-
.catch(constVoid)
2581+
withinViewerDeadline(session.send("Page.stopScreencast"))
25842582
.then(() => session.detach())
25852583
.catch(constVoid),
25862584
),

0 commit comments

Comments
 (0)