docs: public static void loop(Listener listener, final GlobalStateInfo globalInfo,
        final List<HostAddress> addresses,
        SearchFilter searchFilter) throws SQLException {
  
      MasterProtocol protocol;
      ArrayDeque<HostAddress> loopAddresses = new ArrayDeque<>(addresses);
      if (loopAddresses.isEmpty()) {
        resetHostList(listener, loopAddresses);
      }
  
      int maxConnectionTry = listener.getRetriesAllDown();
      boolean firstLoop = true;
      SQLException lastQueryException = null;
      while (!loopAddresses.isEmpty() || (!searchFilter.isFailoverLoop() && maxConnectionTry > 0)) {
        protocol = getNewProtocol(listener.getProxy(), globalInfo, listener.getUrlParser());
  
        if (listener.isExplicitClosed()) {
          return;
        }
        maxConnectionTry--;
  
        try {
          HostAddress host = loopAddresses.pollFirst();
          if (host == null) {
            loopAddresses.addAll(listener.getUrlParser().getHostAddresses());
            host = loopAddresses.pollFirst();
          }
          protocol.setHostAddress(host);
          protocol.connect();
          if (listener.isExplicitClosed()) {
            protocol.close();
            return;
          }
          listener.removeFromBlacklist(protocol.getHostAddress());
          listener.foundActiveMaster(protocol);
          return;
  
        } catch (SQLException e) {
          listener.addToBlacklist(protocol.getHostAddress());
          lastQueryException = e;
        }
  
        // if server has try to connect to all host, and master still fail
        // add all servers back to continue looping until maxConnectionTry is reached
        if (loopAddresses.isEmpty() && !searchFilter.isFailoverLoop() && maxConnectionTry > 0) {
          resetHostList(listener, loopAddresses);
          if (firstLoop) {
            firstLoop = false;
          } else {
            try {
              //wait 250ms before looping through all connection another time
              Thread.sleep(250);
            } catch (InterruptedException interrupted) {
              //interrupted, continue
            }
          }
  
        }
  
      }
      if (lastQueryException != null) {
        throw new SQLException(
            "No active connection found for master : " + lastQueryException.getMessage(),
            lastQueryException.getSQLState(), lastQueryException.getErrorCode(), lastQueryException);
      }
      throw new SQLException("No active connection found for master");
    }