Repository navigation
Conversation
createDepsOptimizer().close() cancels the in-flight scan/optimize but does not resolve the current or enqueued depOptimizationProcessing promises. A dependency discovered into the current batch while an optimize run is in flight then keeps a forever-pending optimizedDepInfo.processing, so its vite:optimized-deps load() awaits info.processing forever and DevEnvironment.close()'s pending-request drain never completes -> close() never resolves. Mirror runOptimizer()'s pre-optimize closed guard, which already resolves both. Fixes vitejs#22934
This branch has not been deployed
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
createDepsOptimizer().close()cancels the in-flight scan/optimize but does not resolve the current or enqueueddepOptimizationProcessingpromises. If a dependency is discovered into the current batch while an optimize run is in flight (after that run'sstartNextDiscoveredBatch()but before it finishes) and the server is then closed, that dep'soptimizedDepInfo.processingis left pending forever. Itsvite:optimized-depsload()awaitsinfo.processingforever, so the request never leavesenvironment._pendingRequestsandDevEnvironment.close()'s pending-request drain loop never completes —close()never resolves and the process hangs at teardown.This mirrors
runOptimizer()'s pre-optimizeclosedguard, which already resolves both the current and the enqueued promises;close()just needs to do the same.Fixes #22934.
Reproduction
Minimal, deterministic repro (Vitest browser mode): https://github.com/bent0b0x/vite-optimizer-orphan-hang —
npm testhangs on unpatched vite (reproduced on 8.0.8 and 8.1.4); applying this change makes it exit cleanly.Note on tests
The failure is a teardown timing race — a dependency discovered mid-optimize plus
close()landing while that optimize run is in flight — which is hard to express as a stable unit test without artificial timing hooks. The linked reproduction triggers it deterministically. Happy to add a test in whatever form maintainers prefer.