Problem Statement/Rationale
Seems like multiple writes to stdio directly from a singe mongosh evaluation leaks listeners on the mongosh cli interrupt implementation, this doesn't seem to break anything but produces an unexpected warning in the output
Steps to Reproduce
mongosh --nodb --quiet --eval "for (let i = 0; i < 11; i++) { console.log('hi'); }"
Expected Results
hi is printed on the screen eleven times
Actual Results
hi is printed on the screen eleven times but also a warning about max listeners:
> for (let i = 0; i < 11; i++) { console.log('hi'); }; (node:33596) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 interrupted listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit (Use `node --trace-warnings ...` to show where the warning was created) hi hi hi hi hi hi hi hi hi hi hi
Additional Notes
- Using print instead of console.log directly avoids causing the issue
- It doesn't matter if it's stdout or stderr, changing console.log to console.error in the example above still causes the issue