Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak just including the module #10

Open
jessewilliams1 opened this issue Jul 17, 2019 · 17 comments
Open

Memory leak just including the module #10

jessewilliams1 opened this issue Jul 17, 2019 · 17 comments
Assignees

Comments

@jessewilliams1
Copy link

jessewilliams1 commented Jul 17, 2019

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

@joelcolucci
Copy link
Owner

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

@joelcolucci joelcolucci self-assigned this Jul 17, 2019
@jessewilliams1
Copy link
Author

jessewilliams1 commented Jul 17, 2019

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;
};

@joelcolucci
Copy link
Owner

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

@adesege
Copy link

adesege commented Aug 6, 2019

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.

@joelcolucci
Copy link
Owner

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

@adesege
Copy link

adesege commented Aug 7, 2019

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

@glownesWlc
Copy link

@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

@joelcolucci
Copy link
Owner

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

@joelcolucci
Copy link
Owner

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.

@extremerotary
Copy link

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

@extremerotary
Copy link

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.

@joelcolucci
Copy link
Owner

@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?

@extremerotary
Copy link

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

@Trunksome
Copy link

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?

@joelcolucci
Copy link
Owner

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.

@lencyforce
Copy link

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.

@Trunksome
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants