Skip to content

[BUG] Version error and memory leak #8040

@LaurensRietveld

Description

@LaurensRietveld

Do you want to request a feature or report a bug?
Bug

What happens:

  • After recently updating mongoose, we've experienced a memory leak.
  • When saving a document, a version-error is created and saved to this.$__.$versionError
  • When creating this version error it runs a captureStacktrace command. Capturing the stack means references to it's stack (for us that included CLS, requests, etc) are retained. This is related to this nodejs issue
  • As a result, the errors and their stack are not garbage collected. With many save operations this would cause our process to run out of memory

Why this didnt happen before

  • In this commit the versionerror is stored in this.$__.$versionError instead of options.$versionError
  • The options object is cleaned up after a save (see here). The this.$__.$versionError however isnt

Workaround

  • Using a post-save hook that deletes this.$__.$versionError

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose: 5.6.3
node: v10.16.0
mongo: 3.4.1

cc @thombohlk

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions