<commit_before>module ZTK
  class SSH

    # SSH Core Functionality
    module Core

      # Starts an SSH session.  Can also be used to get the Net::SSH object.
      #
      # Primarily used internally.
      def ssh
        @ssh ||= Net::SSH.start(config.host_name, config.user, ssh_options)
        @ssh
      end

      # Starts an SFTP session.  Can also be used to get the Net::SFTP object.
      #
      # Primarily used internally.
      def sftp
        @sftp ||= self.ssh.sftp
        @sftp
      end

      # Close our session gracefully.
      def close
        config.ui.logger.debug { "close" }

        if (@ssh && !@ssh.closed?)
          begin
            @ssh.close
          rescue EOFError
            # NOOP
          end
        end

        @ssh = nil
        @sftp = nil

        true
      end

      # The on_retry method we'll use with the RescueRetry class.
      def on_retry(exception)
        config.ui.logger.warn { "ZTK::SSH on_retry triggered!" }

        (close rescue false)
      end

    end

  end
end<commit_msg>refactor the SSH close method; eat all exceptions; added debug logger statements<commit_after>module ZTK
  class SSH

    # SSH Core Functionality
    module Core

      # Starts an SSH session.  Can also be used to get the Net::SSH object.
      #
      # Primarily used internally.
      def ssh
        @ssh ||= Net::SSH.start(config.host_name, config.user, ssh_options)
        @ssh
      end

      # Starts an SFTP session.  Can also be used to get the Net::SFTP object.
      #
      # Primarily used internally.
      def sftp
        @sftp ||= self.ssh.sftp
        @sftp
      end

      # Close our session gracefully.
      def close
        config.ui.logger.debug { "close" }

        if (!@ssh.nil? && !@ssh.closed?)
          config.ui.logger.debug { "SSH object is valid and not closed" }

          begin
            config.ui.logger.debug { "attempting to close" }
            @ssh.close
            config.ui.logger.debug { "closed" }

          rescue Exception => e
            config.ui.logger.fatal { "EXCEPTION: #{e.inspect}" }
          end

        else
          config.ui.logger.debug { "SSH object is NIL!" }
        end

        @ssh = nil
        @sftp = nil

        true
      end

      # The on_retry method we'll use with the RescueRetry class.
      def on_retry(exception)
        config.ui.logger.warn { "ZTK::SSH on_retry triggered!" }

        (close rescue false)
      end

    end

  end
end
{'fraction_non_alphanumeric': 0.08561093247588425, 'fraction_numerical': 0.0, 'mean_word_length': 1.628299894403379, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7348830', 'n_tokens_mistral': 804, 'n_tokens_neox': 740, 'n_words': 235}