Skip to content

Passing an object to the createJob(job) method, which is the result of a database query, may cause a memory leak. #885

@OlegKolesnikoff

Description

@OlegKolesnikoff

Passing an object to the createJob(job) method, which is the result of a database query via mongoose, leads to a memory leak. Despite the fact that the object has been queued and the task is waiting in the Redis storage, the object continues to occupy space in heap space old, if there are a lot of tasks, then memory consumption increases. The memory is cleared only when the task is completed, as the reference to the object becomes irrelevant.

When transferring a regular object, for example, if you use a lean database query, this is not observed.

Most likely, the reason lies deeper and it's not about the mongoose object.

I don't think this is a problem with library, but it might be worth mentioning it in the description, as it can save a lot of time for developers.

router.route('/example').post(async (req, res, next) => {
  try {
    res.status(200).end();
    const query = await Item.findOne({'id':1});
    queue.createJob(job).save(query);
  } catch (err) {
    next(err);
  }
});

This is probably due to the fact that one way or another the query result refers to an external library that is called in the global scope, which means that this case applies to any other library that creates an object.

The expected behavior is that all references will be destroyed when the object is queued...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions