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

Change the Implementation of get() in MultiItemCache to Prevent Stack Exhaustion #15047

Merged
merged 2 commits into from Jan 11, 2022

Conversation

dtanders
Copy link
Contributor

One of the projects I'm on at work has such a large number of outputs (currently 1400 and growing) and that is causing webpack to crash during compilation. You can see in the stack trace starting here that the same 6 lines repeat a little over 1200 times until the stack is exhausted. This is because the MultiItemCache in lib/CacheFacade.js uses recursion to iterate over it's item list when you call get(). This implementation prevents stack exhaustion both in the included unit test and in my testing with our project. I'm sure it could be more elegantly written but I've taken care to avoid behavioral changes other than preventing our use case from blowing the stack.

What kind of change does this PR introduce?

This is a bugfix for a probably-rare case in which a large number of outputs causes compilation to exhaust the interpreter stack.

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

No

What needs to be documented once your changes are merged?

Nothing that I'm aware of

@linux-foundation-easycla
Copy link

CLA Not Signed

@webpack-bot
Copy link
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

…k exhaustion when it has a large number of items.

Added unit tests for MultiItemCache behavior, including one for covering the large item count case.
@dtanders dtanders force-pushed the Fix-MultiItemCache-Stack-Exhaustion branch from a0ad1d2 to 9c6557e Compare December 23, 2021 17:25
@sokra sokra merged commit 753fdea into webpack:main Jan 11, 2022
@sokra
Copy link
Member

sokra commented Jan 11, 2022

Thanks

@dtanders
Copy link
Contributor Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants