node-quill-converter icon indicating copy to clipboard operation
node-quill-converter copied to clipboard

Memory leak just including the module

Open jessewilliams1 opened this issue 5 years ago • 17 comments

node.js 10.10.0
npm 6.4.1
express: 4.17.1

Memory usage went from 60MB (normal) to 450MB over 9 hours by simply including the module:

const quillConverter = require('node-quill-converter');

Screen Shot 2019-07-17 at 3 23 55 PM

jessewilliams1 avatar Jul 17 '19 22:07 jessewilliams1

Hi @jessewilliams1 Thanks for submitting this. I'll look into it.

joelcolucci avatar Jul 17 '19 22:07 joelcolucci

This looks suspiciously like an infinite loop if it were called:

document.execCommand = function (command, showUI, value) {
  try {
      return document.execCommand(command, showUI, value);
  } catch(e) {}
  return false;
};

jessewilliams1 avatar Jul 17 '19 22:07 jessewilliams1

Hmmm. I'll test it out. Thanks for your patience.

joelcolucci avatar Jul 21 '19 22:07 joelcolucci

Hey @joelcolucci, the leak is probably due to the JSDOM library and the fact that you are reading the quill file synchronously. That could have an impact when converting large files.

The reason why the leak occurs by just including the file is that the reading of the file is done at the top level. So whether you use the package or not, it will always read the files.

I'm using this package locally and how I solved it is by using fs.promises.readFile and instead of using require.resolve, I used path.join to get the full path to quill.min.js file.

The performance improved greatly.

adesege avatar Aug 06 '19 15:08 adesege

Thanks @adesege. I'll try out those adjustments. I appreciate your time and feedback.

joelcolucci avatar Aug 07 '19 02:08 joelcolucci

You are welcome man! The package gave me a good start though. Thanks.

adesege avatar Aug 07 '19 12:08 adesege

@joelcolucci Is memory leak issue resolved now? I have to convert HTML to Delta on nodejs server side. So i need this package to implement on node side

glownesWlc avatar Nov 21 '19 11:11 glownesWlc

Hi all, thank you for your patience. I am dedicating some time this week to revisit this issue. Will update soon.

joelcolucci avatar Jan 22 '20 00:01 joelcolucci

Hi all! Just published version ^0.3.3 which improves memory usage and prevents the module from hanging on import.

It looks like Quill's setText method eats up a lot of memory. I'm going to continue to troubleshoot. Let me know if you all have any questions.

joelcolucci avatar Jan 24 '20 00:01 joelcolucci

@joelcolucci Thanks a million for looking into this! I'm going to get the version updated next week and submit my findings.

extremerotary avatar Jan 24 '20 00:01 extremerotary

Unfortunately, in my testing, there is still a memory leak. I updated to version 0.3.3 and let the node server run on the server. It took about 2 days, but the memory usage kept increasing until it ran out of memory.

extremerotary avatar Feb 11 '20 13:02 extremerotary

@extremerotary Thanks for the feedback.

In my testing I noticed that a potential leak occurs when calling Quill.setContents. Quill might have a circular reference preventing the garbage collector from cleaning things up. I'm away this weekend but will dive back in next week.

Are you using this in a web application or an ETL pipeline?

joelcolucci avatar Feb 14 '20 23:02 joelcolucci

@joelcolucci Hey Joel, We use it in a web application.

extremerotary avatar Feb 15 '20 02:02 extremerotary

I experienced the same issue after including the module in a nodejs app. I use it to convert quill delta to HTML.

See memory usage in blue:

Screenshot 2020-10-07 at 09 46 09

nodejs 14.9.0 npm 6.14.7 express 4.17.1 node-quill-converter 0.3.3

At the moment, I simply require the module like so: const { convertDeltaToHtml } = require("node-quill-converter"); and then use it when needed: convertDeltaToHtml(delta); Is there anything I should be doing differently?

Trunksome avatar Oct 07 '20 07:10 Trunksome

Hey @Trunksome, thanks for letting me know. I'm backed up work up at the moment. I'll try and spin up a long running process and see if I can replicate, isolate this issue.

joelcolucci avatar Oct 22 '20 01:10 joelcolucci

Hi @joelcolucci really nice work on this project! Is there any update on this issue? I'm using the module the same way as @Trunksome, and the service is eating up lots of memory and dies frequently.

lencyforce avatar Feb 24 '21 13:02 lencyforce

I ended up closing this library and wrapping everything in a class (thereby only creating a JSDOM when needed) and calling

close() {
    this.cache = null;
    this.DOM.window.close(); // found it here: https://stackoverflow.com/questions/13893163/jsdom-and-node-js-leaking-memory
}

once i'm finished with the converter. Memory leaks are gone.

Trunksome avatar Aug 09 '21 15:08 Trunksome