Node.js driver 3.2.x leaking timers running in Node.js v12

We where having some memory filling up and some base line CPU usage increase in our Node.js applications. The cause seems to be the MongoB driver. After some investigation we found out that the “mongodb-core”-package (being used in mongodb v3.0.x - v3.2.x) is leaking timers due to changes in timers for Node.js v12.

The MongoDB Node.js driver versions 3.0.x till 3.2.x are reported to support Node.js v12.x.x here:

Is it possible to change the compatibility matrix or is the the bug going to be fixed? So people won’t run into the same issues while using older driver versions.


Timer list being filtered by “isRunning”:

“isRunning” implementation using “_called”:

Node.js pull request containing the removal of the “_called” variable (lib/timers.js line 282):

Hi @Wilco_Waaijer!
Thanks for bringing this to our attention. I’ve actually already been working on a fix for this on NODE-2460, and hope to have a fix out today.

Regarding the compatibility matrix: we’re up to v3.5.4 of the driver now, so it’s unlikely that we will backport the fix three minor versions back. Generally we don’t backport changes within a major unless it is security related. In this case the recommendation is to upgrade to v3.5.x, where the fix will land shortly. I’ll get in touch with our docs team to correct the compatibility matrix.

Additionally, you can avoid this issue today by upgrading to v3.5.4 and using the “unified topology” by passing { useUnifiedTopology: true } to your MongoClient constructor, or useUnifiedTopology=true to your connection string.


Perfect. I was not aware that there was an issue for that already. We are upgrading and depending on the release of the fix look into the unified topology option.

It would indeed be nice if others are warned about the possible leak while running in Node.js v12 with the older versions. Is it okay if i comment on the issue with this thread or just the way to avoid the issue with the unified topology option? An extra way for people to find a solution if they’re searching for more info regarding the leak.

Thank you for taking the time to provide some more information!

The issue has been fixed in this commit. Feel free to link to this page on the ticket.

We are looking for as much feedback as possible on the unified topology, since we’ll be completely removing the legacy topology types in the upcoming v4 major release. Please let us know if you decide to use it, and about your experience with it!