    # File lib/active_support/vendor/memcache-client-1.6.5/memcache.rb, line 604
      def with_socket_management(server, &block)
        check_multithread_status!

        @mutex.lock if @multithread
        retried = false

        begin
          socket = server.socket

          # Raise an IndexError to show this server is out of whack. If were inside
          # a with_server block, we'll catch it and attempt to restart the operation.

          raise IndexError, "No connection to server (#{server.status})" if socket.nil?

          block.call(socket)

        rescue SocketError => err
          logger.warn { "Socket failure: #{err.message}" } if logger
          server.mark_dead(err)
          handle_error(server, err)

        rescue MemCacheError, SystemCallError, IOError => err
          logger.warn { "Generic failure: #{err.class.name}: #{err.message}" } if logger
          handle_error(server, err) if retried || socket.nil?
          retried = true
          retry
        end
      ensure
        @mutex.unlock if @multithread
      end