Skip to content

Commit d02d7e9

Browse files
committed
PR feedback
1 parent c1e594b commit d02d7e9

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

src/Grpc.Net.Client/Balancer/BalancerAttributes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private BalancerAttributes(Dictionary<string, object?> attributes, bool readOnly
7272
ICollection<string> IDictionary<string, object?>.Keys => _attributes.Keys;
7373
ICollection<object?> IDictionary<string, object?>.Values => _attributes.Values;
7474
int ICollection<KeyValuePair<string, object?>>.Count => _attributes.Count;
75-
bool ICollection<KeyValuePair<string, object?>>.IsReadOnly => _readOnly ? true : ((ICollection<KeyValuePair<string, object?>>)_attributes).IsReadOnly;
75+
bool ICollection<KeyValuePair<string, object?>>.IsReadOnly => _readOnly || ((ICollection<KeyValuePair<string, object?>>)_attributes).IsReadOnly;
7676
IEnumerable<string> IReadOnlyDictionary<string, object?>.Keys => _attributes.Keys;
7777
IEnumerable<object?> IReadOnlyDictionary<string, object?>.Values => _attributes.Values;
7878
int IReadOnlyCollection<KeyValuePair<string, object?>>.Count => _attributes.Count;

src/Grpc.Net.Client/Balancer/Subchannel.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void UpdateAddresses(IReadOnlyList<BalancerAddress> addresses)
176176
var currentAddress = CurrentAddress;
177177
if (currentAddress != null)
178178
{
179-
if (!HasMatchingEndpoint(_addresses, currentAddress))
179+
if (GetAddressByEndpoint(_addresses, currentAddress.EndPoint) != null)
180180
{
181181
SubchannelLog.ConnectedAddressNotInUpdatedAddresses(_logger, Id, currentAddress);
182182
requireReconnect = true;
@@ -406,36 +406,30 @@ internal void RaiseStateChanged(ConnectivityState state, Status status)
406406
}
407407
}
408408

409-
internal BalancerAddress? GetAddress(DnsEndPoint? endpoint)
409+
internal BalancerAddress? GetAddress(DnsEndPoint? endPoint)
410410
{
411-
if (endpoint != null)
411+
if (endPoint != null)
412412
{
413413
lock (Lock)
414414
{
415-
foreach (var address in _addresses)
416-
{
417-
if (address.EndPoint.Equals(endpoint))
418-
{
419-
return address;
420-
}
421-
}
415+
return GetAddressByEndpoint(_addresses, endPoint);
422416
}
423417
}
424418

425419
return null;
426420
}
427421

428-
private static bool HasMatchingEndpoint(List<BalancerAddress> addresses, BalancerAddress currentAddress)
422+
private static BalancerAddress? GetAddressByEndpoint(List<BalancerAddress> addresses, DnsEndPoint endPoint)
429423
{
430424
foreach (var a in addresses)
431425
{
432-
if (a.EndPoint.Equals(currentAddress.EndPoint))
426+
if (a.EndPoint.Equals(endPoint))
433427
{
434-
return true;
428+
return a;
435429
}
436430
}
437431

438-
return false;
432+
return null;
439433
}
440434

441435
/// <inheritdocs />

0 commit comments

Comments
 (0)