Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2123

MaxListenersExceededWarning caused by topologyDescriptionChanged

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.4
    • Affects Version/s: 3.3.0
    • Component/s: None
    • Labels:

      I recently added `useUnifiedTopology: true` to my connection options.

      let options = {
         keepAlive: 120,
         connectTimeoutMS: process.env.MONGO_TIMEOUT * 1000,
         socketTimeoutMS: process.env.MONGO_TIMEOUT * 1000,
         useNewUrlParser: true,
         useUnifiedTopology: true,
         ignoreUndefined: true
      };
      mongoClient.connect(process.env.MONGO_URI, options, (error, client) => {
        ...
      
      });
      

      I am currently running a three member replica set (primary, secondary and arbiter).

      When I stop my primary using `service mongod stop`, the election process occurs and the secondary becomes the primary. All is good so far.

      Problem is I get the following `MaxListenersExceededWarning` warning on my application servers running the latest version of https://www.npmjs.com/package/mongodb and sometimes a `MongoTimeoutError` causes them to crash.

      I haven't noticed this issue on other application servers using Mongoose.

      *MaxListenersExceededWarning*

      (node:23551) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 topologyDescriptionChanged listeners added. Use emitter.setMaxListeners() to increase limit
      

      *MongoTimeoutError*

      MongoTimeoutError: Server selection timed out after 10000 ms
      File "/home/lickstats-admin/lickstats-router/node_modules/mongodb/lib/core/sdam/topology.js", line 851, col 16, in Timeout.setTimeout [as _onTimeout]
      callback(new MongoTimeoutError(`Server selection timed out after ${timeout} ms`));
      File "timers.js", line 436, col 11, in ontimeout
      File "timers.js", line 300, col 5, in tryOnTimeout
      File "timers.js", line 263, col 5, in listOnTimeout
      File "timers.js", line 223, col 10, in Timer.processTimers
      

      Is there a bug with the new topology?

      Thanks,

      Sun

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            sun@lickstats.com Sun Knudsen
            Votes:
            2 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: