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: explicitly define property for entity relation as enumerable #9437

Conversation

orcwarrior
Copy link
Contributor

@orcwarrior orcwarrior commented Oct 6, 2022

Description of change

Change to makes properties for entity relation explicitly non-enumerable, which resolves a "rare" issue that leads to a memory leak.

In some environments it seems like an entity object was created with column values set to undefined, thus Object.defineProperty uses already defined value for enumerable - true. This leads to RawSqlResultsToEntityTransformer.transform() run-getters on relation fields (as they were enumerable) resolving the promises - running queries which eventually leads to the Free memory exhaustion on the machine :)

Closes: #6631

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply prettier formatting
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

Unfortunately while trying to find a way to replicate the issue in a couple of ways:

  • Trying to make entity class derivative of BaseEntity
  • Trying to run compiled tests
  • Replicating my project entities in close to 1:1 way

I wasn't able to replicate the same behavior in the test case, but while debugging I found exactly the same behavior in my code as other users reported in the issue.

Making enumerable: false explicitly stated shouldn't regress any code and seems like running tests locally confirmed that, however single test did fail:

UP: I see that on CI tests worked just fine

    In some environments it seems like entity object was created with columns values set to undefined, thus Object.defineProperty uses already defined value for enumerable - true.
    Which leads to RawSqlResultsToEntityTransformer.transform() run getters on relation fields (as they were enumerable) resolving the promises - running queries which eventually leads to the Free memory exhaustion on the machine :)

    Closes: typeorm#6631
@orcwarrior orcwarrior marked this pull request as ready for review October 6, 2022 03:22
@AlexMesser AlexMesser merged commit 85fa9c6 into typeorm:master Nov 5, 2022
@AlexMesser
Copy link
Collaborator

thank you for contribution!

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.

Memory leak in lazy relation
2 participants