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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not overwrite pendingReload promise (fix #5448) #5452

Merged
merged 2 commits into from
Oct 28, 2021

Conversation

Artur-
Copy link
Contributor

@Artur- Artur- commented Oct 27, 2021

Description

In case of this call sequence

  1. registerMissingImport
  2. a new incoming request
  3. registerMissingImport

the request in step 2 will keep waiting indefinitely for a promise that will never resolve as step 3 overwrites the _pendingReload promise without resolving the previous one

Fixes #5448

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

fix vitejs#5448)

In case of this call sequence
1. registerMissingImport
2. a new incoming request
3. registerMissingImport

the request in step 2 will keep waiting indefinitely for a promise that will never resolve as step 3 overwrites the _pendingReload promise without resolving the previous one

Fixes vitejs#5448
@Artur- Artur- changed the title fix: Do not overwrite pendingReload promise so all requests can finish fix: Do not overwrite pendingReload promise so all requests can finish (fix #5448) Oct 27, 2021
Shinigami92
Shinigami92 previously approved these changes Oct 27, 2021
Comment on lines +97 to +101
if (!server._pendingReload) {
server._pendingReload = new Promise((r) => {
pendingResolve = r
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would fix the case where we have:

  • registerMissing -> save pendingResolveA
  • registerMissing
  • rerun
    ... after rerun is completed -> pendingResolveA()
  • registerMissing -> save pendingResolveB
  • transformRequest waiting for pendingResolveB

If registerMissingImport is called while rerun is running, we would be resolving newly

  • registerMissing -> save pendingResolveA
  • registerMissing
  • rerun
  • registerMissing (... while rerun is completed)
  • transformRequest waiting for pendingResolveA
    ... after rerun is completed -> pendingResolveA()

Now there is a rerun enqueued, but _pendingReload is null. This wasn't happening before
Another thing is that if there are missing deps already, it may be better to make these requests wait for the next rerun directly. But that may be a bigger change.

Maybe on rerun, we should save the current pendingResolve that correspond to the currentMissing for this run, and then nullify it. So, if there is a new registerMissing call and we see that pendingResolve is null, we can recreate _pendingReload fixing the second series above

Copy link
Contributor Author

@Artur- Artur- Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't realize rerun was async so registerMissing can be called while rerun is being executed.

I made a new version that tries to wait for all rerun operations to complete before resolving the promise. Not sure this is what you were looking for (or that it will work in all cases)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏼
Thanks!

@patak-dev patak-dev requested a review from Shinigami92 October 28, 2021 07:23
@patak-dev patak-dev changed the title fix: Do not overwrite pendingReload promise so all requests can finish (fix #5448) fix: do not overwrite pendingReload promise (fix #5448) Oct 28, 2021
@patak-dev patak-dev merged commit cc9c2da into vitejs:main Oct 28, 2021
@Artur- Artur- deleted the fix-pendingreload branch October 28, 2021 08:08
@haoqunjiang haoqunjiang mentioned this pull request Dec 9, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server stops handling requests when requesting many files during initial startup
3 participants