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

Fix(@inquirer/core): Destroy output stream on exit. #1499

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

atikassam
Copy link
Contributor

This PR fixes the memory leak warning below

(node:2670733) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 drain listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 drain listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit

    at _addListener (node:events:591:17)
    at WriteStream.addListener (node:events:609:10)
    at WriteStream.Readable.on (node:internal/streams/readable:928:35)
    at MuteStream.Stream.pipe (node:internal/streams/legacy:33:8)
    at MuteStream.pipe (/xxxxx/node_modules/mute-stream/lib/index.js:73:18)
    at Object.prompt (/xxxxx/node_modules/@inquirer/core/dist/cjs/lib/create-prompt.js:46:16)
    at ProgramsInterface.<anonymous> (/xxxxx/xxxxx/xxxxx:24:40)
    at Generator.next (<anonymous>)
    at /xxxxx/xxxxx/xxxxx/xxxxx:14:71

Copy link

codecov bot commented Aug 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@056e26a). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1499   +/-   ##
=======================================
  Coverage        ?   97.59%           
=======================================
  Files           ?       37           
  Lines           ?     2243           
  Branches        ?      573           
=======================================
  Hits            ?     2189           
  Misses          ?       48           
  Partials        ?        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@SBoudrias
Copy link
Owner

Thanks! Do you have an example code where this triggers? I'd like to reproduce myself, and try to add a unit test to ensure it doesn't regress.

@SBoudrias SBoudrias merged commit 04323b3 into SBoudrias:main Aug 5, 2024
10 checks passed
@atikassam
Copy link
Contributor Author

Thanks! Do you have an example code where this triggers? I'd like to reproduce myself, and try to add a unit test to ensure it doesn't regress.

import * as prompts from '@inquirer/prompts';

async function main() {
  for (let i = 0; i < 15; i++) {
    let ans = await prompts.input({ message: `Type ${i}` });
    console.log('Your typed:', ans)
  }
}

main();

process.on('warning', e => console.warn(e.stack));

Output:

.
.
.
? Type 8 
Your typed: 
? Type 9 
Your typed: 
? Type 10 (node:62585) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 drain listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 drain listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:587:17)
    at WriteStream.addListener (node:events:605:10)
    at WriteStream.Readable.on (node:internal/streams/readable:887:35)
    at MuteStream.Stream.pipe (node:internal/streams/legacy:33:8)
    at MuteStream.pipe (/xxx/xxx/xxx/node_modules/mute-stream/lib/index.js:73:18)
    at Object.prompt (/xxx/xxx/xxx/node_modules/@inquirer/core/dist/cjs/lib/create-prompt.js:45:16)
    at /xxx/xxx/xxx/src/m.ts:5:29
    at Generator.next (<anonymous>)
    at fulfilled (/xxx/xxx/xxx/src/m.ts:28:58)
(node:62585) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:587:17)
    at WriteStream.prependListener (node:events:619:14)
    at prependListener (node:internal/streams/legacy:100:20)
    at MuteStream.Stream.pipe (node:internal/streams/legacy:67:3)
    at MuteStream.pipe (/xxx/xxx/xxx/node_modules/mute-stream/lib/index.js:73:18)
    at Object.prompt (/xxx/xxx/xxx/node_modules/@inquirer/core/dist/cjs/lib/create-prompt.js:45:16)
    at /xxx/xxx/xxx/src/m.ts:5:29
    at Generator.next (<anonymous>)
    at fulfilled (/xxx/xxx/xxx/src/m.ts:28:58)
(node:62585) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:587:17)
    at WriteStream.addListener (node:events:605:10)
    at WriteStream.Readable.on (node:internal/streams/readable:887:35)
    at MuteStream.Stream.pipe (node:internal/streams/legacy:89:8)
    at MuteStream.pipe (/xxx/xxx/xxx/node_modules/mute-stream/lib/index.js:73:18)
    at Object.prompt (/xxx/xxx/xxx/node_modules/@inquirer/core/dist/cjs/lib/create-prompt.js:45:16)
    at /xxx/xxx/xxx/src/m.ts:5:29
    at Generator.next (<anonymous>)
    at fulfilled (/xxx/xxx/xxx/src/m.ts:28:58)

@SBoudrias
Copy link
Owner

I could reproduce in both test and demos, but for me destroy didn't remove the warning. end did however, so I adjusted the code accordingly (incl. the regression test!)

Thanks for the help!

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

Successfully merging this pull request may close these issues.

2 participants