schickling / chromeless

🖥 Chrome automation made simple. Runs locally or headless on AWS Lambda.
https://chromeless.netlify.com
MIT License
13.24k stars 575 forks source link

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added. Use emitter.setMaxListeners() to increase limit #180

Open aml11 opened 7 years ago

aml11 commented 7 years ago

When reusing the same Chromeless proxy object I get MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added. Use emitter.setMaxListeners() to increase limit

This is consistent and can be easily reproduced using this snippet:

import {Chromeless} from 'chromeless'
declare var document: any;

async function run() {
    const remote = {};
    const chromeless = new Chromeless(
        {
            remote: {
                endpointUrl: 'XXXXX',
                apiKey: 'XXXXX'
            },
        }
    );
    for (let site of ["https://google.com", "https://amazon.com", "https://apple.com", "https://google.com", "https://amazon.com", "https://apple.com"]) {
        const title = await chromeless
            .goto(site)
            .evaluate(() => {
                return document.title
            });
        console.log(title) // prints local file path or S3 url
    }

    await chromeless.end()
}

run().catch(console.error.bind(console))

Will output:

Google
Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more
Apple
Google
(node:8059) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:281:19)
    at MqttClient.addListener (events.js:298:10)
    at /Users/amir/dev/test/testVideosFb/node_modules/chromeless/dist/src/chrome/remote.js:186:47
    at MqttClient.subscribe (/Users/amir/dev/test/testVideosFb/node_modules/mqtt/lib/client.js:484:5)
    at /Users/amir/dev/test/testVideosFb/node_modules/chromeless/dist/src/chrome/remote.js:185:43
    at Promise (<anonymous>)
    at RemoteChrome.<anonymous> (/Users/amir/dev/test/testVideosFb/node_modules/chromeless/dist/src/chrome/remote.js:184:35)
    at step (/Users/amir/dev/test/testVideosFb/node_modules/chromeless/dist/src/chrome/remote.js:32:23)
    at Object.next (/Users/amir/dev/test/testVideosFb/node_modules/chromeless/dist/src/chrome/remote.js:13:53)
    at fulfilled (/Users/amir/dev/test/testVideosFb/node_modules/chromeless/dist/src/chrome/remote.js:4:58)
Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more
Apple

I deployed version Chromeless version 1.0.1 (due to #99 ) both locally and remotely.

adieuadieu commented 7 years ago

@aml11 thanks for bringing this up. We're aware of the EventEmitter memory leak and have a fix coming for it soon.

skunkwerk commented 6 years ago

This seems to have been fixed in 1.3, so I think we can close this.

zelphir commented 6 years ago

Still getting the same error

davidworkman9 commented 6 years ago

Also getting this with node v8.8.1

Raidus commented 6 years ago

any updates on this? getting the same warning

achyutjhunjhunwala commented 6 years ago

+1

dlumma commented 6 years ago

I am also getting this issue currently.

dlumma commented 6 years ago

Is there a workaround suggested?

Nisthar commented 6 years ago

@dlumma Does it use less memory if i deploy chromeless to aws?

beyer-martin commented 6 years ago

Getting the same warning

dragg commented 6 years ago

I solved this warning with next code: require('events').EventEmitter.defaultMaxListeners = 30;. But I still have performance issue (my script executing during 20-30 seconds on AWS) as it was with the warning.