-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Circular dependencies in SSR not detected and causes indefinite hang #2491
Labels
Comments
antimatter15
changed the title
Circular dependencies in SSR sometimes not detected and causes indefinite hang
Circular dependencies in SSR not detected and causes indefinite hang
Mar 13, 2021
aral
added a commit
to small-tech/domain
that referenced
this issue
Apr 28, 2021
…to work around Vite bug: vitejs/vite#2491
fairbanksg
added a commit
to fairbanksg/vite
that referenced
this issue
May 19, 2021
9 tasks
9 tasks
fairbanksg
added a commit
to fairbanksg/vite
that referenced
this issue
Jun 7, 2021
@fairbanksg I've improved your fix with another case: A -> B means: B is imported by A and B has A in its stack
A ... B means: A is waiting for B to ssrLoadModule()
H -> [X] ... (Y)
H -> [X] -> (Y) ... {B}
H -> A -> {B} ... |M|
H -> A -> {B} -> |M| ... [X]
Deadlock description:
[X] is waiting for (Y) to resolve
which is waiting for {B}
which is waiting for |M|
which is waiting for [X]
H is the first module in common by all modules https://github.com/raythurnevoid/vite/commit/4bffced904bb04c32ae48084cbda1fb156e26e9e |
10 tasks
aleclarson
pushed a commit
to aleclarson/vite
that referenced
this issue
Jun 24, 2021
aleclarson
pushed a commit
to aleclarson/vite
that referenced
this issue
Jul 16, 2021
aleclarson
pushed a commit
to aleclarson/vite
that referenced
this issue
Jul 29, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
Let's say we have three files: A, B, and C, where A is the entry point. B and C cyclically depend on each other. A depends on both B and C. In this situation, Vite will not detect the cyclic dependency and simply hang indefinitely.
Reproduction
Create the following 3 files inside of the
src/pages
directory of thessr-react
playground. Attempt to load the/A
page, and notice that it hangs forever and the logs are empty.Explanation
This bug happens because
ssrLoadModule
first gets called with A, the entry point. WithininstantiateModule
, it then tries to load the dependencies B and C in parallel, and caches their promises in thependingModules
map.When
instantiateModule
finally runs on B, it blocks untilssrLoadModule
completes for its sole dependency: C. WhenssrLoadModule
is called, theurlStack
only has[A, B]
so it bypasses the circular dependency test. Since C is already in thependingModules
map, it returns the existing promise waiting for C to load.Essentially this results in a state where A depends on B and C, while B and C both depend on each other. At this point
ssrLoadModule
will never complete.System Info
vite
version: 2.0.5The text was updated successfully, but these errors were encountered: