lib/mongo/server/connection_pool.rb
# Check a connection back into the pool.
#
# The connection must have been previously created by this pool.
#
# @param [ Mongo::Server::Connection ] connection The connection.
#
# @since 2.9.0
Check a connection back into the pool.
The connection must have been previously created by this pool.
Check a connection back into the pool . The connection must have been previously created by this pool .
def check_in(connection)
        check_invariants
        @lock.synchronize do
          unless connection.connection_pool == self
            raise ArgumentError, "Trying to check in a connection which was not checked out by this pool: #{connection} checked out from pool #{connection.connection_pool} (for #{self})"
          end
          unless @checked_out_connections.include?(connection)
            raise ArgumentError, "Trying to check in a connection which is not currently checked out by this pool: #{connection} (for #{self})"
          end
          @checked_out_connections.delete(connection)
          publish_cmap_event(
            Monitoring::Event::Cmap::ConnectionCheckedIn.new(@server.address, connection.id, self)
          )
          if connection.error?
            connection.disconnect!(reason: :error)
            return
          end
          if closed?
            connection.disconnect!(reason: :pool_closed)
            return
          end
          if connection.closed?
            @populate_semaphore.signal
          elsif connection.generation != generation(service_id: connection.service_id)
            connection.disconnect!(reason: :stale)
            @populate_semaphore.signal
          else
            connection.record_checkin!
            @available_connections << connection
            @available_semaphore.signal
          end
        end
      ensure
        check_invariants
      end
def check_in ( connection ) check_invariants @lock . synchronize do unless connection . connection_pool == self raise ArgumentError , "Trying to check in a connection which was not checked out by this pool: #{connection} checked out from pool #{connection.connection_pool} (for #{self})" end unless @checked_out_connections . include? ( connection ) raise ArgumentError , "Trying to check in a connection which is not currently checked out by this pool: #{connection} (for #{self})" end @checked_out_connections . delete ( connection ) publish_cmap_event ( Monitoring :: Event :: Cmap :: ConnectionCheckedIn . new ( @server . address , connection . id , self ) ) if connection . error? connection . disconnect! ( reason : :error ) return end if closed? connection . disconnect! ( reason : :pool_closed ) return end if connection . closed? @populate_semaphore . signal elsif connection . generation != generation ( service_id : connection . service_id ) connection . disconnect! ( reason : :stale ) @populate_semaphore . signal else connection . record_checkin! @available_connections << connection @available_semaphore . signal end end ensure check_invariants end
Check a connection back into the pool.
Check a connection back into the pool .
# Note: if an event handler raises, resource will not be signaled. # This means threads waiting for a connection to free up when # the pool is at max size may time out. # Threads that begin waiting after this method completes (with # the exception) should be fine. # Connection was closed - for example, because it experienced # a network error. Nothing else needs to be done here. # Wake up only one thread waiting for an available connection, # since only one connection was checked in.
connection
connection The connection.
connection The connection .
since
None