Skip to content

Commit 9c41784

Browse files
authored
Fix TestClock interrupting masked finalizers during warning setup (#10520)
1 parent edb2eaa commit 9c41784

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
Fix `TestClock` interrupting an uninterruptible finalizer on its first sleep and skipping subsequent cleanup.

‎packages/effect/src/testing/TestClock.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ class TestClockImpl implements TestClock {
377377
Effect.provideService(Console.Console, this.liveConsole),
378378
Effect.delay(this.config.warningDelay),
379379
this.withLive,
380+
// Child fibers are interruptible by default; preserve the caller's mask.
380381
Effect.forkChild,
381-
Effect.interruptible,
382382
Effect.flatMap((fiber) =>
383383
Effect.sync(() => {
384384
this.warningState = WarningState.Pending({ fiber })

‎packages/effect/test/TestClock.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,28 @@ describe("TestClock", () => {
103103
assert.isTrue(elapsed)
104104
}))
105105

106+
it.effect("sleep - preserves interruption masking in a finalizer on first use", () =>
107+
Effect.gen(function*() {
108+
const clock = yield* TestClock.make()
109+
const events: Array<string> = []
110+
const fiber = yield* Effect.never.pipe(
111+
Effect.ensuring(Effect.gen(function*() {
112+
events.push("cleanup started")
113+
yield* Effect.sleep("1 second")
114+
events.push("cleanup finished")
115+
})),
116+
Effect.provideService(Clock.Clock, clock),
117+
Effect.forkChild({ startImmediately: true })
118+
)
119+
fiber.interruptUnsafe()
120+
yield* Effect.yieldNow
121+
assert.deepStrictEqual(events, ["cleanup started"])
122+
assert.isUndefined(fiber.pollUnsafe())
123+
yield* clock.adjust("1 second")
124+
yield* Fiber.await(fiber)
125+
assert.deepStrictEqual(events, ["cleanup started", "cleanup finished"])
126+
}))
127+
106128
it.effect("sleep - handles multiple sleeps", () =>
107129
Effect.gen(function*() {
108130
let message = ""

0 commit comments

Comments
 (0)