<commit_before>class WebsocketServer
  Pairing = Struct.new(:is_ws, :proxy)

  def initialize
    @pairing = {}
    @sockets = Concurrent::Array.new

    Thread.new do
      errors = []
      loop do
        begin
          reads, writes, errors = IO.select(@sockets, @sockets, @sockets, 1)
        rescue IOError
          cleanup(errors)
        end

        # Skip this loop if we can't do anything
        if Array(reads).empty? || writes.empty? || errors.any?
          sleep(1) if @sockets.empty?
          next
        end

        # Do the data transfers
        reads.each do |read|
          @pairing[read].proxy.transmit(writes, @pairing[read].is_ws)
        end<commit_msg>Clean up sockets which disconnected between two IO.select calls<commit_after>class WebsocketServer
  Pairing = Struct.new(:is_ws, :proxy)

  def initialize
    @pairing = {}
    @sockets = Concurrent::Array.new

    Thread.new do
      errors = []
      loop do
        begin
          reads, writes, errors = IO.select(@sockets, @sockets, @sockets, 1)
        rescue IOError
          cleanup(errors)
        end

        # Skip this loop if we can't do anything
        if Array(reads).empty? || writes.empty? || errors.any?
          sleep(1) if @sockets.empty?
          next
        end

        # Do the data transfers
        reads.each do |read|
          begin
            @pairing[read].proxy.transmit(writes, @pairing[read].is_ws)
          rescue
            cleanup(errors)
          end
        end
{'fraction_non_alphanumeric': 0.09819639278557114, 'fraction_numerical': 0.0026720106880427524, 'mean_word_length': 1.8918918918918919, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '320428', 'n_tokens_mistral': 454, 'n_tokens_neox': 436, 'n_words': 119}