Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(optimizer): prevent hang if server closed quickly #16497

Closed
wants to merge 1 commit into from

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Apr 22, 2024

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):

try {
// This is an entry point, it may still not be bundled
await info.processing
} catch {

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:

function startNextDiscoveredBatch() {
newDepsDiscovered = false
// Add the current depOptimizationProcessing to the queue, these
// promises are going to be resolved once a rerun is committed
depOptimizationProcessingQueue.push(depOptimizationProcessing)
// Create a new promise for the next rerun, discovered missing
// dependencies will be assigned this promise from this point
depOptimizationProcessing = promiseWithResolvers()
}

The new depOptimizationProcessing wasn't being resolved since it's not added to depOptimizationProcessingQueue. 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.

@bluwy bluwy added the p3-minor-bug An edge case that only affects very specific usage (priority) label Apr 22, 2024
Copy link

stackblitz bot commented Apr 22, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@bluwy
Copy link
Member Author

bluwy commented Apr 22, 2024

Hmm I don't quite understand why the tests is failing (as it worked locally for me). I'll try to investigate soon but if not, I don't think it's a big need to get this fixed.

@bluwy
Copy link
Member Author

bluwy commented Apr 29, 2024

Closing for now

@bluwy bluwy closed this Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant