-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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: deadlock in ssrLoadModule with circular dependencies (fixes #2491, fixes #2258) #3473
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Is it possible to provide tests so we prevent regression?
@Shinigami92 I would be happy to add some tests for this, but would appreciate some pointers on the best way to do that for this code. It seems like I would need to start a ViteDevServer in middleware mode and then call ssrLoadModule with it. I guess I would need to create a temp directory to have some test code in that I could load? |
@fairbanksg there are currently two ssr playgrounds, ssr-vue and ssr-react. We could create a new playground but I think you could add a test case like the one described in #2491 to one of them. Here is the server calling ssrLoadModule in ssr-vue for example:
The tests for each playground are in the __tests__ dir: https://github.com/vitejs/vite/blob/main/packages/playground/ssr-vue/__tests__/ssr-vue.spec.ts, in case you need to add a new check. Let me know if you want more info. There is a section about this also here https://github.com/vitejs/vite/blob/main/.github/contributing.md#extending-the-test-suiteIf we get a lot of similar cases to test, we may want to split them later into a new playground. |
@patak-js I am working on the test for this, but am running into some trouble running the tests. Even just running them on I added some logging, and it seems like the change that is being tested is happening, so I'm not sure why the tests doesn't see it. These are the steps I took to run the tests.
|
There seems to be an issue (probably a race condition) with the SSR tests that makes them fails sometimes. But I don't know if that is what you are hitting here. The suite is running correctly most of the time now. |
I added some circular dependencies to the ssr-react playground and verified the tests fail without my changes and pass with them. |
@fairbanksg I've opened a pull request to your branch to improve this fix: fairbanksg#1 |
Closing in favor of #3950 |
Description
While
ssrLoadModule
has code to detect circular dependencies, it is possible for some to not be detected.For example, if two modules directly import each other, and some other module imports both of those, the import path can lead to
urlStack
not showing the circular dependency. The end result is that the two modules will await each other's pending promises and deadlock.This change will check that no dependencies of a pending module are in the
urlStack
, which would lead to a deadlock.Additionally, the
ssrModule
is set on theModuleNode
immediately so that the reference is constant, allowing circular dependencies to access exports when they later become available.Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).