Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Aug 29, 2023
1 parent c1e594b commit d02d7e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Balancer/BalancerAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private BalancerAttributes(Dictionary<string, object?> attributes, bool readOnly
ICollection<string> IDictionary<string, object?>.Keys => _attributes.Keys;
ICollection<object?> IDictionary<string, object?>.Values => _attributes.Values;
int ICollection<KeyValuePair<string, object?>>.Count => _attributes.Count;
bool ICollection<KeyValuePair<string, object?>>.IsReadOnly => _readOnly ? true : ((ICollection<KeyValuePair<string, object?>>)_attributes).IsReadOnly;
bool ICollection<KeyValuePair<string, object?>>.IsReadOnly => _readOnly || ((ICollection<KeyValuePair<string, object?>>)_attributes).IsReadOnly;
IEnumerable<string> IReadOnlyDictionary<string, object?>.Keys => _attributes.Keys;
IEnumerable<object?> IReadOnlyDictionary<string, object?>.Values => _attributes.Values;
int IReadOnlyCollection<KeyValuePair<string, object?>>.Count => _attributes.Count;
Expand Down
22 changes: 8 additions & 14 deletions src/Grpc.Net.Client/Balancer/Subchannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void UpdateAddresses(IReadOnlyList<BalancerAddress> addresses)
var currentAddress = CurrentAddress;
if (currentAddress != null)
{
if (!HasMatchingEndpoint(_addresses, currentAddress))
if (GetAddressByEndpoint(_addresses, currentAddress.EndPoint) != null)
{
SubchannelLog.ConnectedAddressNotInUpdatedAddresses(_logger, Id, currentAddress);
requireReconnect = true;
Expand Down Expand Up @@ -406,36 +406,30 @@ internal void RaiseStateChanged(ConnectivityState state, Status status)
}
}

internal BalancerAddress? GetAddress(DnsEndPoint? endpoint)
internal BalancerAddress? GetAddress(DnsEndPoint? endPoint)
{
if (endpoint != null)
if (endPoint != null)
{
lock (Lock)
{
foreach (var address in _addresses)
{
if (address.EndPoint.Equals(endpoint))
{
return address;
}
}
return GetAddressByEndpoint(_addresses, endPoint);
}
}

return null;
}

private static bool HasMatchingEndpoint(List<BalancerAddress> addresses, BalancerAddress currentAddress)
private static BalancerAddress? GetAddressByEndpoint(List<BalancerAddress> addresses, DnsEndPoint endPoint)
{
foreach (var a in addresses)
{
if (a.EndPoint.Equals(currentAddress.EndPoint))
if (a.EndPoint.Equals(endPoint))
{
return true;
return a;
}
}

return false;
return null;
}

/// <inheritdocs />
Expand Down

0 comments on commit d02d7e9

Please sign in to comment.