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(query): clone PopulateOptions when setting _localModel to avoid state leaking between subpopulate instances #15082

Merged
merged 5 commits into from
Dec 11, 2024

Conversation

vkarpov15
Copy link
Collaborator

Summary

#15026 is a very tricky bug where sometimes _localModel populate option leaks between subpopulate instances. I wasn't able to find the exact root cause to my satisfaction, nor was I able to come up with a consistent repro that doesn't involve repeatedly running the repro script from #15026. However, the more high level explanation is that utils.populate() doesn't clone instances of PopulateOptions, so PopulateOptions instances are shared between nested populate calls. This PR makes it so that we clone populate options before setting _localModel.

Also, to aid in debugging, I went ahead and refactored populate internals to use async/await instead of callbacks. Should be much cleaner.

Examples

lib/model.js Outdated Show resolved Hide resolved
@vkarpov15 vkarpov15 added this to the 8.9 milestone Dec 11, 2024
@vkarpov15 vkarpov15 merged commit 2241823 into master Dec 11, 2024
73 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-15026 branch December 11, 2024 17:04
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.

2 participants