Method: Mongo::Server::ConnectionPool#close_idle_sockets

Defined in:
lib/mongo/server/connection_pool.rb

#close_idle_socketsObject

Close sockets that have been open for longer than the max idle time,

if the option is set.

Since:

  • 2.5.0



735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'lib/mongo/server/connection_pool.rb', line 735

def close_idle_sockets
  return if closed?
  return unless max_idle_time

  @lock.synchronize do
    i = 0
    while i < @available_connections.length
      connection = @available_connections[i]
      if last_checkin = connection.last_checkin
        if (Time.now - last_checkin) > max_idle_time
          connection.disconnect!(reason: :idle)
          @available_connections.delete_at(i)
          @populate_semaphore.signal
          next
        end
      end
      i += 1
    end
  end
end