Driver does not close pipes when a connection is closed

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Critical - P2
    • 2.21.2
    • Affects Version/s: None
    • Component/s: Connections
    • None
    • None
    • Ruby Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      An example to reproduce the issue:

      def count_open_pipes(pid = Process.pid)
        `lsof -p #{pid} | grep PIPE | wc -l`.to_i
      end
      
      uri = 'mongodb://localhost:27017,localhost:27018,localhost:27019/pipes'
      NUM_CONNECTIONS = 10
      ITERATIONS = 100
      
      ITERATIONS.times do |iter|
        clients = []
      
        NUM_CONNECTIONS.times do
          client = Mongo::Client.new(uri, database: 'test')
          clients << client
        end
      
        # Do something (list collections)
        clients.each do |client|
          client.database.collection_names
        end
      
        # Close clients
        clients.each(&:close)
      
        puts "Iteration #{iter+1}: Open pipes: #{count_open_pipes}"
        sleep 0.5
      end
      

      The output is:

      Iteration 1: Open pipes: 23
      Iteration 2: Open pipes: 43
      Iteration 3: Open pipes: 63
      Iteration 4: Open pipes: 83
      Iteration 5: Open pipes: 103
      Iteration 6: Open pipes: 123
      Iteration 7: Open pipes: 143
      Iteration 8: Open pipes: 163
      Iteration 9: Open pipes: 183
      Iteration 10: Open pipes: 203
      ...
      

      The pipe objects left open, and the application that uses the driver crashes with Errno::EMFILE Too many open files error.

              Assignee:
              Dmitry Rybakov
              Reporter:
              Dmitry Rybakov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: