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

MaxListenersExceededWarning with fs.createReadStream #78

Open
jmikrut opened this issue Mar 28, 2023 · 1 comment
Open

MaxListenersExceededWarning with fs.createReadStream #78

jmikrut opened this issue Mar 28, 2023 · 1 comment

Comments

@jmikrut
Copy link

jmikrut commented Mar 28, 2023

Hi there and thank you for this package!

I am seeing a MaxListenersExceededWarning while using createReadStream and probe-image-size like follows:

    const readStream = fs.createReadStream(filePath);
    const result = await probeImageSize(readStream);

It seems to be coming from this package. Here is the full error with node --trace-warnings:

(node:74217) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:587:17)
    at PassThrough.addListener (node:events:605:10)
    at PassThrough.Readable.on (node:internal/streams/readable:887:35)
    at eos (node:internal/streams/end-of-stream:196:10)
    at pipe (node:internal/streams/pipeline:392:10)
    at pipelineImpl (node:internal/streams/pipeline:323:25)
    at pipeline (node:internal/streams/pipeline:151:10)
    at probeStream (/MY-PROJECT-PATH/node_modules/probe-image-size/stream.js:63:8)
    at Object.get_image_size [as default] (/MY-PROJECT-PATH/node_modules/probe-image-size/index.js:13:12)

I've adjusted the code to not use a createReadStream and instead read the full file to memory first as follows:

    const data = fs.readFileSync(filePath)
    const result = await probe.sync(data)

Issue goes away. Is this indeed caused by something within probe-image-size? It appears so on my end but can't figure out how to resolve / diagnose further.

One other thing I should note is that we did try to destroy and close the readStream after having used it. For example:

    const readStream = fs.createReadStream(filePath);
    const result = await probeImageSize(readStream);
    readStream.destroy() // also tried `close()`

But this does not fix the warning either.

Any ideas?

@rlidwka
Copy link
Member

rlidwka commented May 26, 2023

Didn't I fix this in a6da059? Maybe you're using old version (which may happen because of some other dependency).

Or the error might've reappeared elsewhere. In this case, please provide full example that we can run as is.

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