Skip to content

Commit 60a613c

Browse files
committed
Fix double disposal in shutdown test and remove unused drain from CoalescingDrainableWorker
- Make dispose() in Manager.test.ts idempotent with a disposed guard so the afterEach cleanup does not double-close the scope/runtime. - Remove the unused drain property from CoalescingDrainableWorker interface and implementation since no consumer of this worker type uses it.
1 parent 4772126 commit 60a613c

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

apps/server/src/terminal/Layers/Manager.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ async function makeManager(
211211
).pipe(Effect.forkIn(eventScope)),
212212
);
213213

214+
let disposed = false;
214215
return {
215216
baseDir,
216217
logsDir,
@@ -221,6 +222,8 @@ async function makeManager(
221222
run: <A, E>(effect: Effect.Effect<A, E>) => runtime.runPromise(effect),
222223
getEvents: () => Effect.runPromise(Ref.get(eventsRef)),
223224
dispose: async () => {
225+
if (disposed) return;
226+
disposed = true;
224227
await Effect.runPromise(Scope.close(eventScope, Exit.void));
225228
await runtime.dispose();
226229
},

packages/shared/src/CoalescingDrainableWorker.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { Effect, TxQueue, TxRef } from "effect";
1313
export interface CoalescingDrainableWorker<K, V> {
1414
readonly enqueue: (key: K, value: V) => Effect.Effect<void>;
1515
readonly drainKey: (key: K) => Effect.Effect<void>;
16-
readonly drain: Effect.Effect<void>;
1716
}
1817

1918
interface CoalescingWorkerState<K, V> {
@@ -126,16 +125,6 @@ export const makeCoalescingDrainableWorker = <K, V, E, R>(options: {
126125
Effect.asVoid,
127126
);
128127

129-
const drain: CoalescingDrainableWorker<K, V>["drain"] = TxRef.get(stateRef).pipe(
130-
Effect.tap((state) =>
131-
state.latestByKey.size > 0 || state.queuedKeys.size > 0 || state.activeKeys.size > 0
132-
? Effect.txRetry
133-
: Effect.void,
134-
),
135-
Effect.asVoid,
136-
Effect.tx,
137-
);
138-
139128
const drainKey: CoalescingDrainableWorker<K, V>["drainKey"] = (key) =>
140129
TxRef.get(stateRef).pipe(
141130
Effect.tap((state) =>
@@ -147,5 +136,5 @@ export const makeCoalescingDrainableWorker = <K, V, E, R>(options: {
147136
Effect.tx,
148137
);
149138

150-
return { enqueue, drainKey, drain } satisfies CoalescingDrainableWorker<K, V>;
139+
return { enqueue, drainKey } satisfies CoalescingDrainableWorker<K, V>;
151140
});

0 commit comments

Comments
 (0)