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 in Windows #887

Closed
dantasfiles opened this issue Feb 1, 2020 · 12 comments
Closed

MaxListenersExceededWarning in Windows #887

dantasfiles opened this issue Feb 1, 2020 · 12 comments

Comments

@dantasfiles
Copy link

I run packages/inquirer/examples/recursive.js.
In 7.0.4 (latest) on Windows, I get a MaxListenersExceededWarning:

> node recursive.js
? What's your favorite TV show? 1
? Want to enter another TV show favorite (just hit enter for YES)? Yes
? What's your favorite TV show? 2
? Want to enter another TV show favorite (just hit enter for YES)? Yes
? What's your favorite TV show? 3
? Want to enter another TV show favorite (just hit enter for YES)? Yes
? What's your favorite TV show? 4
? Want to enter another TV show favorite (just hit enter for YES)? Yes
? What's your favorite TV show? 5
? Want to enter another TV show favorite (just hit enter for YES)? Yes
? What's your favorite TV show? 6
? Want to enter another TV show favorite (just hit enter for YES)? Yes
? What's your favorite TV show? 7
? Want to enter another TV show favorite (just hit enter for YES)? Yes
? What's your favorite TV show? 8
? Want to enter another TV show favorite (just hit enter for YES)? Yes
? What's your favorite TV show? 9
? Want to enter another TV show favorite (just hit enter for YES)? Yes
? What's your favorite TV show? (node:40212) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [ReadStream]. Use emitter.setMaxListeners() to increase limit
(node:40212) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 keypress listeners added to [ReadStream]. Use emitter.setMaxListeners() to increase limit    
? What's your favorite TV show? 10
? Want to enter another TV show favorite (just hit enter for YES)? No
Your favorite TV Shows: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

The MaxListenersExceededWarning occurs in 7.0.4 and 7.0.2

It does not occur in 7.0.3 and <=7.0.1.

My environment is

 System:
    OS: Windows 10 10.0.18363
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
    Memory: 1.19 GB / 7.85 GB
  Binaries:
    Node: 13.7.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.13.6 - C:\Program Files\nodejs\npm.CMD
@attilah
Copy link

attilah commented Feb 27, 2020

@SBoudrias I've diagnosed this issue while trying to fix it in Amplify CLI where we're leveraging Inquirer to drive the console prompts.
The root cause is that every prompt creates a new RXJS Observable to the process' stdin, and event based observables can only be released if they're subscribed and the subscription's unsubscribe method is called. Since inquirer only using RXJS operators it does not happen. Only the Editor prompt uses subscription, but only for the line and not for keypress. A single prompt or a prompt list lifecycle could handle it in a clean way, the very same way as Editor does, unsubscribed from keypress in onEnd handler. Since the same problem exist in extensions it would be better to handle in a higher level.
Another solution would be to just create the Observable object once and reuse it between prompts as stdin "rarely changes", but events.js could manage a list of rl objects and hand over the proper observable based on the rl object reference. /cc @dantasfiles

@rizzlesauce
Copy link

@SBoudrias is it possible that this bug is caused by #882 (03412e5)? It appears that change makes it so that the readline interface does not get closed on windows.

@SBoudrias
Copy link
Owner

@rizzlesauce that's possible; but closing the readline on windows was making the prompt unresponsive.

The best solution on the longer term is probably moving away from rxjs altogether. I've made a lot of progress on this #692 - but I'm running out of time to complete a release.

I'm okay to review a PR if anyone wants to take the time.

@nanomosfet
Copy link

this is happening in 7.3.3 of inquierer

going to have to move off this package for this reason

@SBoudrias
Copy link
Owner

@nanomosfet take a look at the @inquirer/* prompts (https://github.com/SBoudrias/Inquirer.js/tree/master/packages/input and the other). They're simpler interfaces and should be faster. All core prompts are already re-implemented in that fashion, checkout the other packages in the monorepo to see them all.

@Kief5555
Copy link

I am getting memory leaks on 8.2.4 on trace it seems like NXJS is cauing this issue.

@SBoudrias
Copy link
Owner

Yeah, rxjs has been a problematic dependency for memory leaks. Like I said, the new prompts under the @inquirer/* namespace aren't relying on it for this reason; and they're available on npm if you want to give them a try.

@Kief5555
Copy link

Kief5555 commented Jul 22, 2022

Hi,

Can I have a direct link?
Also I cannot update inquirer due to the fact I am using pkg package to distribute my app, pkg does not support esm

@SBoudrias
Copy link
Owner

@ethereal-engineer
Copy link

This is also happening on Linux, but it has been fine until recently so I am not entirely sure what happened.

@SBoudrias
Copy link
Owner

Closing this ticket as stale. Open new issues if you encounter problems with the new Inquirer API.

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

8 participants
@rizzlesauce @attilah @SBoudrias @ethereal-engineer @dantasfiles @nanomosfet @Kief5555 and others