Memory leak using findAll method
See original GitHub issueIssue Description
What are you doing?
Iterating over Postgres DB data via findAll method with limit and offset params. Here is the minimal reproducible code:
import { Model } from './models';
void (async () => {
let currentOffset = 0;
const queryData = async (offset = 0) => {
await Model.findAll({
limit: 10000,
offset,
});
await queryData(currentOffset += 10000);
};
await queryData();
})();
What do you expect to happen?
The code runs fine and doesn’t cause memory leaks.
What is actually happening?
Node.js process grows in memory consumption over time and causes a memory leak and process exit.
Output here
Additional context
Here is the similar issue, which was closed by the bot.
Environment
- Sequelize version: 6.3.5
- Node.js version: 14.15.4
- Operating System: Ubuntu 20.04
- TypeScript version: 4.1.3
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don’t know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don’t know how to start, I would need guidance.
- No, I don’t have the time, although I believe I could do it if I had the time…
- No, I don’t have the time and I wouldn’t even know how to start.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:24 (8 by maintainers)
Top Results From Across the Web
Memory Leak when using PrincipalSearcher.FindAll()
But the trick is that FindAll itself returns an object that must be disposed... using (var searchResults = searcher.FindAll()) { foreach ( ...
Read more >C# – Memory Leak when using PrincipalSearcher.FindAll()
But the trick is that FindAll itself returns an object that must be disposed... using (var searchResults = searcher.FindAll()) { foreach (GroupPrincipal result ......
Read more >Memory Leak when using DirectorySearcher.FindAll() - C#
Memory Leak when using DirectorySearcher. FindAll () - C# [ Glasses to protect eyes while coding : https://amzn.to/3N1ISWI ] Memory Leak when ...
Read more >[Solved]-UIAutomation FindAll leaks memory-C - appsloveworld
The result of the findAll method is an IUIAutomationElementArray returned through the out-parameter array . array contains multiple IUIAutomationElement ...
Read more >Find a Memory Leak | dotMemory Documentation - JetBrains
In this tutorial, we'll see how you can use dotMemory to locate and fix memory leaks in your apps. But before moving on,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I ran some load testing.
Here’s a heap snapshot before, with Sequelize taking around 1.5MB
And then here’s 6 hours after the load testing was over:
As you can see, Sequelize hasn’t released 114MB worth of memory (~48% of the Node process).
handleSelectQuery() seems to be the culprit.
Note: We are using Sequelize 6.6.2, Postgres 9.6, Node 14.16.0 and Ubuntu 16.0.4
@ephys here is a repo and way to reproduce https://github.com/hironate/sequelize-memory-leak