mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 20:53:00 +00:00
fix(process): observe already-due trailing callbacks before settling the capture journal (#1700)
A stalled event loop can leave the settle wake-up and a trailing observation callback due at the same resume. The earlier wake-up runs first, declares silence, and the capture becomes immutable before the trailing callback appends its observation. Drain the loop turn after the quiet sleep so timer and poll callbacks that were already due run before silence is judged, and cover the stalled-loop case with a deterministic regression test. Fixes #1697
This commit is contained in:
1 parent
66c21572de
commit
ed084b3dbb
2 files changed
+32
-1
No files matched your search
@@ -3,7 +3,7 @@ import { constants, statSync, type BigIntStats } from "node:fs";
|
||||
import { open, mkdtemp, rm, stat } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import { setImmediate, setTimeout as delay } from "node:timers/promises";
|
||||
import type { IPty } from "@lydell/node-pty";
|
||||
|
||||
import type { ProcessCapture } from "../../domain/process/processCaptureParsing.js";
|
||||
@@ -271,6 +271,10 @@ export const settleProcessCaptureJournal = async (
|
||||
let lastChangeAt = Date.now();
|
||||
while (Date.now() < deadline) {
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, 4));
|
||||
// A stalled event loop can leave timer and poll callbacks that were already
|
||||
// due queued behind this wake-up. Drain them before judging silence so a
|
||||
// trailing observation is not dropped by an early settle.
|
||||
await setImmediate();
|
||||
if (journal.length !== observed) {
|
||||
observed = journal.length;
|
||||
lastChangeAt = Date.now();
|
||||
|
||||
Reference in new issue
Block a user