public async Task <KuduConnection> GetConnectionAsync(
        ServerInfo serverInfo, CancellationToken cancellationToken = default)
    {
        if (_disposed)
        {
            ThrowObjectDisposedException();
        }

        IPEndPoint            endpoint = serverInfo.Endpoint;
        Task <KuduConnection>?connectionTask;
        bool newConnection = false;

        lock (_connections)
        {
            if (!_connections.TryGetValue(endpoint, out connectionTask))
            {
                connectionTask = _connectionFactory.ConnectAsync(serverInfo, cancellationToken);
                _connections.Add(endpoint, connectionTask);
                newConnection = true;
            }
        }

        try
        {
            var connection = await connectionTask.ConfigureAwait(false);

            if (newConnection)
            {
                connection.ConnectionClosed.UnsafeRegister(
                    state => RemoveConnection((IPEndPoint)state !),
                    endpoint);
            }

            return(connection);
        }
        catch (Exception ex)
        {
            // Failed to negotiate a new connection.
            RemoveFaultedConnection(endpoint);

            _logger.UnableToConnectToServer(ex, serverInfo);

            if (ex is NonRecoverableException)
            {
                // Always retry, except for these.
                throw;
            }

            // The upper-level caller should handle the exception and
            // retry using a new connection.
            throw new RecoverableException(
                      KuduStatus.NetworkError(ex.Message), ex);
        }
    }
 public NoLeaderFoundException(string message, Exception?innerException)
     : base(KuduStatus.NetworkError(message), innerException)
 {
 }