docs: private void handleKey(SelectionKey key) throws IOException {
          // We could have a !isValid() key here if the connection is already closed at this point
          if (key.isValid() && key.isConnectable()) { // ie a client connection which has finished the initial connect process
              // Create a ConnectionHandler and hook everything together
              PendingConnect data = (PendingConnect) key.attachment();
              StreamConnection connection = data.connection;
              SocketChannel sc = (SocketChannel) key.channel();
              ConnectionHandler handler = new ConnectionHandler(connection, key, connectedHandlers);
              try {
                  if (sc.finishConnect()) {
                      log.info("Connected to {}", sc.socket().getRemoteSocketAddress());
                      key.interestOps((key.interestOps() | SelectionKey.OP_READ) & ~SelectionKey.OP_CONNECT).attach(handler);
                      connection.connectionOpened();
                      data.future.set(data.address);
                  } else {
                      log.warn("Failed to connect to {}", sc.socket().getRemoteSocketAddress());
                      handler.closeConnection(); // Failed to connect for some reason
                      data.future.setException(new ConnectException("Unknown reason"));
                      data.future = null;
                  }
              } catch (Exception e) {
                  // If e is a CancelledKeyException, there is a race to get to interestOps after finishConnect() which
                  // may cause this. Otherwise it may be any arbitrary kind of connection failure.
                  // Calling sc.socket().getRemoteSocketAddress() here throws an exception, so we can only log the error itself
                  Throwable cause = Throwables.getRootCause(e);
                  log.warn("Failed to connect with exception: {}: {}", cause.getClass().getName(), cause.getMessage(), e);
                  handler.closeConnection();
                  data.future.setException(cause);
                  data.future = null;
              }
          } else // Process bytes read
              ConnectionHandler.handleKey(key);
      }