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

Infinitely hangs inserting complex document with recursive schema #14897

Closed
2 tasks done
hunkydoryrepair opened this issue Sep 20, 2024 · 3 comments · Fixed by #14910
Closed
2 tasks done

Infinitely hangs inserting complex document with recursive schema #14897

hunkydoryrepair opened this issue Sep 20, 2024 · 3 comments · Fixed by #14910
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@hunkydoryrepair
Copy link

hunkydoryrepair commented Sep 20, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.4.1+

Node.js version

20.x

MongoDB server version

5.x,6.x

Typescript version (if applicable)

5.4.5

Description

mongoose_test.zip

This test case demonstrates inserting a single document with a complex schema. it is actually simplified from out actual schema in use, and I've replace several subdocuments with Mixed. But I expect it is very likely due to the potential recursive nature of the schema.

Works as expected in version 8.2.2, 8.3.0 and 8.4.0.
Hangs in 8.4.1 - 8.6.3

Steps to Reproduce

build and run attached app.

Expected Behavior

inserts the document.

@hunkydoryrepair
Copy link
Author

Note, when simplifying the schema and replacing other portions with .Mixed, it does not hang, leading me to believe this is not a mongo driver bug.

@hunkydoryrepair
Copy link
Author

hunkydoryrepair commented Sep 20, 2024

There appears to be an infinite loop in isDirectModified

Although, I don't understand if debugger is showing the correct values. I don't see how .join could return undefined with these values

image

@hunkydoryrepair
Copy link
Author

I see...it isn't that it is INFINITE. It is just effectively infinite. We have a document 40 levels deep and the isDirectModified appears to be on order of N! (factorial). So it will run until we are all dead, but not infinitely.
I know a document 40 levels deep is extreme and we've improved our document generation techniques since this document was made. But it worked fine on earlier versions.

And I don't understand the why it would need to check each level. If it checks the top level, which recursively checks all of the sublevels, it would then need to check the sublevel separately.
I'm also confused why this even runs on a CREATE call, since nothing is modified, it is a completely new document. Hence, "create"

@vkarpov15 vkarpov15 added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Sep 22, 2024
@vkarpov15 vkarpov15 added this to the 8.6.4 milestone Sep 22, 2024
vkarpov15 added a commit that referenced this issue Sep 24, 2024
vkarpov15 added a commit that referenced this issue Sep 25, 2024
fix(document): avoid massive perf degradation when saving new doc with 10 level deep subdocs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
2 participants