tcort / wkhtmltox

high performance access to `wkhtmltopdf` and `wkhtmltoimage` from node.js.
61 stars 7 forks source link

Memory leak #20

Open btxtiger opened 1 year ago

btxtiger commented 1 year ago

Hi, seems there appears a memory leak, if the converter was instantiated inside the request function.

express1.post('/pdf', (request, response) => {
   const wk = new wkhtmltox();
   response.writeHead(200, { 'Content-Type': 'application/pdf' });
   wk.pdf(strtostr(request.body.html), request.body.wkConfig).pipe(response);
});

If you fire requests to this endpoint, you can see the memory of the node process growing until it gets out of memory. In my case I used docker stats to observe the container memory usage.

The issue does not appear, if the converter was instantiated once at the same level as express().

In some use-cases, a global converter object might not be accessible. How can the instance be destroyed properly after usage?