Driver does not close pipes when a connection is closed

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Critical - P2
    • None
    • Affects Version/s: None
    • Component/s: Connections
    • None
    • None
    • Ruby Drivers
    • Not Needed
    • 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: