fix(server): serialize chokidar watcher batches to prevent heap growth - #1300
Open
Schrotti77 wants to merge 1 commit into
Open
fix(server): serialize chokidar watcher batches to prevent heap growth#1300Schrotti77 wants to merge 1 commit into
Schrotti77 wants to merge 1 commit into
Conversation
chokidar (Windows ReadDirectoryChangesW) emits more granular events than inotify, so a 50ms batch can still be mid-drain (readFile-ing every change) when the next timer fires. Launching batches independently piles up overlapping async work → unbounded heap growth on event storms. Chain batches on an inFlight promise so they drain strictly one at a time. The .catch stays load-bearing: it keeps the chain alive after an error. Regression test: maxActive must stay 1 when a second batch lands mid-drain. Fails without the fix (maxActive=2), passes with it.
|
Thanks for the contribution! What happens next:
|
|
Hermes (Marian's AI Agent) seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Contributor
|
hi @Schrotti77 could you follow the @CLAassistant instructions? and i'll see this through |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows the OK server uses the chokidar watcher fallback (
@parcel/watchercrashes withSTATUS_STACK_BUFFER_OVERRUNon long/non-ASCII paths, see #1207). chokidar (ReadDirectoryChangesW) emits more granular events than inotify, and each 50ms batch callshandleRawEvents, which readFile()s every changed file.When a batch is still mid-drain (slow disk, many files, active sync/backup tool) and the next 50ms timer fires, the new batch launches independently — overlapping async work piles up and the Node heap grows without bound on event storms.
Fix
Serialize batches by chaining them on an
inFlightpromise instartChokidarWatcher. Batches drain strictly one at a time; a batch that lands while another is draining waits its turn. The.catchremains load-bearing: it keeps the chain alive after an error so later batches don't deadlock.Regression test
file-watcher-chokidar-fallback.test.ts— new describe "chokidar backend — batch serialization":active++, hold 200ms,active--), tracksmaxActiveactive === 1(batch 1 draining)expect(maxActive).toBe(1)Verified:
maxActivereaches 2 — batches overlap)Tested with
forceBackend: 'chokidar'on Linux — no Windows needed to exercise the path.