sequelize: Memory Usage Bug

What are you doing?

Using leakage to run a memory test on fetching data by ID. In this case the there is no Task with ID 0

import { iterate } from 'leakage';
import * as models from '../lib/models';

  it('fetch tasks with non-existent id', async function() {
    this.timeout(180000);
    await iterate.async(async () => {
        await (models.Task as any).findById(0);
    }, { iterations: 300 });
  });

FULL PROJECT: https://github.com/aindeev/sequelize-memory-example

What do you expect to happen?

The memory heap to not grow after garbage colleaction

What is actually happening?

MemoryLeakError: Heap grew on 6 subsequent garbage collections (1800 of 1800 iterations) by 595 kB.

  Iterations between GCs: 300

  Final GC details:
  [   36.2 kB] [+  21x] [-   0x] Code
  [   32.7 kB] [+ 280x] [- 172x] Array
  [      16 B] [+  19x] [-  18x] Number
  [       0 B] [+   5x] [-   5x] ArrayBuffer
  ... (6 more)

Is sequelize doing some sort of caching that is making it look like a memory bug? Any ideas what might be going on here?

Dialect: postgres Dialect version: 7.4.1 Database version: (PostgreSQL) 10.1 Sequelize version: 4.37.6 Tested with latest release: Yes (If yes, specify that version)

Note : Your issue may be ignored OR closed by maintainers if it’s not tested against latest version OR does not follow issue template.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 26 (5 by maintainers)

Most upvoted comments

I’m still facing a memory leak issue in v5.9.2. doing update in a while loop seems to be leaking memory

I have the same problem in v5.21.1.

I’m still facing a memory leak issue in v5.9.2. doing update in a while loop seems to be leaking memory

It seems that Sequelize was not the culprit in our case after all. The memory leak issue was caused by another memory leak issue in cls-hooked dependency: https://github.com/Jeff-Lewis/cls-hooked/issues/63 After updating our code according to the discussion in that issue the service seems to perform a lot better (at least for the past 12 hours).

The service I have takes messages from a NATS queue via MoleculerJS and saves the data to the db by performing a Model.create, Model.update, Model.destroy or Model.buildCreate with the data received then returns the result back via NATS. I am currently trying to clean up the code to see if I can isolate the cause to the sequelize calls and not some of the other dependencies (Moleculer, NATS, Prometheus Metrics or async context)… I did try to debug it with the Chrome inspector and I do see references to lodash and bluebird, but it’s hard for me to understand all those references through the Chrome inspector to figure out if they indeed are the cause. I will post another message when I have more details.

@Keimeno Thanks for the reply. I am using it in a docker service based on node:lts-alpine, which should be NodeJS v14.16.1 with Sequelize v5.18.4. I will try to update to NodeJS v15 to see if that might help, but based on the discussion above the issue was in Sequelize v5, not in NodeJS.

This seems to be fixed in V8 version 8.4.371.19-node.17, NodeJS version v14.15.2. @cosmin-harangus what version are you using?