Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1232

Memory leak when multiple Mongo::Client objects initialized

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Works as Designed
    • Affects Version/s: 2.4.3
    • Fix Version/s: None
    • Component/s: Connections
    • Labels:
      None
    • Environment:
      Verified on Linux and macOS

      Description

      Hi,

      First, I must clearly state an important fact: the code referred to uses the MongoDB driver in an incorrect way (as stated here);only one Mongo::Client instance should be created and shared among all threads/requests, even when connection pooling is not desired. However, this used to be our default until today when connection pooling wasn't explicitly enabled, and I noticed it in production because on of our applications were hogging down all memory in the server. Maybe other people would do the same mistake? Anyway, here goes:

      The following gist has a lot of the details around how to reproduce the problem easily, and also how to workaround (= by changing Mongo::Client to only be instantiated once): https://gist.github.com/perlun/c49899bfc2c957ae2b46f2a331f485a1

      As stated above, I am aware that this is "by design" in one sense, since the gem is not intended to be used like this. But clearly, it's easy to make this mistake (if you don't read the documentation carefully enough...).

      I suggest that we either:

      • Fix the gem to properly release memory, or
      • Let Mongo::Client raise an error if it has already been initialized (and consider such scenarios "unsupported").

      Either way is fine with me, I just think that something should be done.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: