Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-919

MaxListenersExceededWarning for interrupted event unexpectedly triggered when writing to the stdio in mongosh in one evaluation

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.0.2
    • Affects Version/s: 1.0.1
    • Component/s: Shell API
    • None
    • 2
    • Not Needed
    • Iteration Hamburg

      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

            Assignee:
            michael.rose@mongodb.com Michael Rose (Inactive)
            Reporter:
            sergey.petushkov@mongodb.com Sergey Petushkov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: