Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/StackExchange.Redis/ConnectionMultiplexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,25 @@ internal ServerSnapshot Add(ServerEndPoint value)
return new ServerSnapshot(arr, _count + 1);
}

internal ServerSnapshot Remove(ServerEndPoint value)
{
if (value == null) return this;
var arr = _arr;
var arrCopy = new ServerEndPoint[arr.Length];
int inserted = 0;
for (int i = 0; i < _count; ++i)
{
if (arr[i] != value)
{
arrCopy[inserted++] = arr[i];
}
}

if (inserted == _count) return this;

return new ServerSnapshot(arrCopy, inserted);
}

internal EndPoint[] GetEndPoints()
{
if (_count == 0) return Array.Empty<EndPoint>();
Expand Down Expand Up @@ -1817,6 +1836,28 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, LogP
// and try to connect to these other nodes in the next iteration
encounteredConnectedClusterServer = true;
updatedClusterEndpointCollection = await GetEndpointsFromClusterNodes(server, log).ForAwait();

if (updatedClusterEndpointCollection?.Count > 0 && server?.EndPoint != null)
{
// if it's a discovery endpoint close it (i.e. endpoint is not in the list of ips returned by cluster nodes command)
var endpointInClusterNodes = updatedClusterEndpointCollection.FirstOrDefault( endpoint => server.EndPoint.Equals(endpoint));
if (endpointInClusterNodes == null)
{
// close the initial cluster discovery connection as it's no longer needed
Task[] closeTask = new Task[2];
closeTask[0] = server.Close(ConnectionType.Interactive);
closeTask[1] = server.Close(ConnectionType.Subscription);
await Task.WhenAll(closeTask);
// server cleanup
lock (this.servers)
{
this.servers.Remove(server.EndPoint);
_serverSnapshot.Remove(server);
}
server.Dispose();
}
continue;
}
}

// set the server UnselectableFlags and update masters list
Expand Down