fix(css): await sass/less/styl worker disposal on teardown (fix #22274)#22275
Merged
bluwy merged 2 commits intoMay 12, 2026
Merged
Conversation
bluwy
reviewed
Apr 21, 2026
dd58617 to
038b819
Compare
bluwy
reviewed
Apr 27, 2026
bluwy
reviewed
Apr 27, 2026
269ef69 to
ceb36e3
Compare
The cssPlugin buildEnd hook and the scss/less/styl processor close methods were synchronous but invoked the asynchronous worker.stop() without awaiting it. server.close() could therefore resolve before the preprocessor workers had actually shut down, leaving their ChildProcess handles alive on the event loop. Make close async end-to-end, dispose the three processors in parallel via Promise.all in createPreprocessorWorkerController, and await the controller from buildEnd.
Address review feedback: only the scss processor's close() actually needs to be async (it awaits compiler.dispose()); less and styl use real artichokie WorkerWithFallback whose stop() is sync. - Widen StylePreprocessor.close to () => void | Promise<void> matching the pattern used elsewhere in the repo - Revert lessProcessor.close and stylProcessor.close to sync - scssProcessor.close stays async (load-bearing) - preprocessorWorkerController.close still awaits Promise.all, which transparently handles the mixed void / Promise<void> returns Also drop unnecessary `port: 0` from the regression test.
ceb36e3 to
f745d9e
Compare
bluwy
approved these changes
May 7, 2026
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.
Description
cssPlugin.buildEnd()andscssProcessor.close()were synchronous but dropped an asyncworker?.stop()promise. On the scss path, that promise awaitscompiler.dispose(), which sends the IPC shutdown to the sass-embedded Dart subprocess — soserver.close()could resolve while the Dart worker was still running, leaving itsChildProcesshandle alive on the event loop.In long-lived processes the event loop eventually reaps the workers. In processes that expect to exit after
server.close()— scripts, programmatic use, Vitest global teardown — the orphanedChildProcesskeeps Node alive.See #22274 for the minimal standalone reproduction and
exitCodebefore/after. Different code path from #18224 (file watchers) but the same user-visible symptom.Changes
cssPlugin.buildEnd: sync →async, awaitspreprocessorWorkerController?.close()scssProcessor.close: sync →async, awaitsworker?.stop()— the only path wherestop()is actually async, sincemakeScssWorkerreturns a hand-rolled object whosestop()awaitscompiler.dispose()createPreprocessorWorkerControllerfan-outclose: sync →async, disposes the three processors in parallel viaPromise.allStylePreprocessor<Options>.closetype:() => void→() => void | Promise<void>(matches the convention used elsewhere in the repo)lessProcessor.closeandstylProcessor.closeare unchanged — they go through realartichokieWorkerWithFallbackwhosestop()is synchronous, so awaiting would be a no-op.On the teardown path,
server.close()now waits for scss'scompiler.dispose()to actually complete before resolving.Tests
New regression test:
packages/vite/src/node/__tests__/plugins/cssPreprocessorTeardown.spec.ts. Starts a dev server, triggers scss transform, asserts no running sassChildProcessafterawait server.close(). Fails onmainwithout this change (expected 1 to be +0).pnpm --filter vite exec vitest run src/node/__tests__/plugins/cssPreprocessorTeardown.spec.tsFixes #22274
AI Disclosure
Used
claude-opus-4-7-thinking-xhighto file the PR.