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

Possible EventEmitter memory leak detected #98

Closed
nendic opened this issue Feb 8, 2021 · 6 comments
Closed

Possible EventEmitter memory leak detected #98

nendic opened this issue Feb 8, 2021 · 6 comments

Comments

@nendic
Copy link

nendic commented Feb 8, 2021

I have a problem when I create multiple images. My application has a timeline, and I convert comments into pictures. When there are several conversions in the tile, then there is a memory leak, and when there are more than 50 of them, the application generally hangs.

error:
(node:124106) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:390:17)
at process.addListener [as on] (events.js:406:10)
at Function.addEventListener (/home/WebstormProjects/works/doc-exporter/node_modules/puppeteer/lib/helper.js:123:17)
at BrowserRunner.start (/home/WebstormProjects/works/doc-exporter/node_modules/puppeteer/lib/Launcher.js:93:35)
at ChromeLauncher.launch (/home/WebstormProjects/works/doc-exporter/node_modules/puppeteer/lib/Launcher.js:205:16)

const docx = require("docx");
const {Paragraph, Media} = docx;
const docHelperFormat = require('../docHelperFormat');
const nodeHtmlToImage = require('node-html-to-image');
const sizeOf = require('image-size');

async function init(item, doc) {
    const arr = [];
    var eventText = '';
    arr.push(
        docHelperFormat.createRoleText('')
    )

    if (!item.parent) {

        eventText = `${item.author.fio} оставил(а) комментарий`;

    } else {

        eventText = `${item.author.fio} процитировал(а) комментарий`;

    }

    const puppeteerArgs = { args: [ '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-accelerated-2d-canvas', '--no-first-run', '--headless', '--no-zygote', '--disable-gpu' ], headless: true, ignoreHTTPSErrors: true };

    arr.push(docHelperFormat.createEventHeader(docHelperFormat.formattedDateFromTS(item.createdAt) + ' ' + eventText));

   const Image = await nodeHtmlToImage({
        html: item.content,
        puppeteerArgs // puppeteerArgs: { args: [ '--no-sandbox', '--disable-setuid-sandbox' ] },
    });

    let dimensions = sizeOf(Image);

    arr.push(
        new Paragraph(
            // docHelperFormat.createRoleText('')
            Media.addImage(doc, Image, dimensions.width, dimensions.height)
        )
    )

    return arr;

}


module.exports = {
    init
}
@frinyvonnick
Copy link
Owner

frinyvonnick commented Feb 8, 2021

Hi @XIIIcool 👋

Thank you for opening this issue. Can you share your environment versions (node, os, ...)?

There is a way to create multiples images with node-html-to-image. Maybe you can generate all your images before. Because using node-html-to-image the way you do it you will spawn a chromium instance for each image. If you don't wait for each iteration to be finished you might spawn a lot a instances.

@nendic
Copy link
Author

nendic commented Feb 8, 2021

node v14.15.1
os ubuntu 20.04
Thank you for your prompt reply. Okay, I'll try to make pictures with one method.

@nendic
Copy link
Author

nendic commented Feb 8, 2021

Bulk image creation solved the problem of memory leaks and application hang. But for some reason in the created pictures the html was not converted, but the code remained. And it would not be bad to transfer a unique identifier to the mass creation of images in the content, so that you can easily extract it.

` async makeTicketEmailImages() {
let content = [];

    this.ticketEmails.forEach((i) =>{
        content.push({
            content: i.content
        })
    })

    const images = await nodeHtmlToImage({
        html: '<html><body>{{content}}</body></html>',
        content: content
    })

    this.ticketEmails.map((val, index) => {
        this.ticketEmails[index].bufferImage = images[index]
        return val;
    })

}`

1

@frinyvonnick
Copy link
Owner

Handlebars seems to escape your html. Here is the documentation about this.

@frinyvonnick
Copy link
Owner

There is a issue about mass creation ordering #85 and one about base64 being escaped that might be linked #89 🤔

@nendic
Copy link
Author

nendic commented Feb 8, 2021

resolved problem, changed {{to {{{, thanks a lot for great support

@nendic nendic closed this as completed Feb 8, 2021
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

2 participants