fix(optimizer): prevent hang if server closed quickly #16497
Closed
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
In a specific case where a Vite server is started up progammatically and quickly closed, if new dependencies were discovered while so,
server.close()
promise will hang because the discovered dependency promises were never resolved, particularly here (which hangs_pendingRequests
):vite/packages/vite/src/node/plugins/optimizedDeps.ts
Lines 49 to 52 in 088d24b
I found the issue that
resolveEnqueuedProcessingPromises()
wasn't called after the server is closing, so I called it. However there's another issue where if it also started a new discovered batch:vite/packages/vite/src/node/optimizer/optimizer.ts
Lines 291 to 301 in 088d24b
The new
depOptimizationProcessing
wasn't being resolved since it's not added todepOptimizationProcessingQueue
. So I flipped line 296 and 300.After these changes, it seem to fix the issue, however it's hard for me to create a test for this scenario 馃槄 I tested this on the Astro test fixtures: withastro/astro@
0b3f1ac
(#10833)I'm not familiar with this area of code, let me know if I had misunderstood the flow and
depOptimizationProcessingQueue
's usecase.