Skip to content

Commit

Permalink
Fixed fatal error in cache host initial connection
Browse files Browse the repository at this point in the history
  • Loading branch information
haneytron committed Dec 13, 2013
1 parent da34786 commit 297ff63
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
17 changes: 7 additions & 10 deletions Dache.Client/CacheClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public CacheClient()
clientContainer.Disconnected += OnClientDisconnected;
clientContainer.Reconnected += OnClientReconnected;

// Attempt to connect
if (!clientContainer.Connect())
{
// Skip it for now
continue;
}

// Add to the client list - constructor so no lock needed over the add here
_cacheHostLoadBalancingDistribution.Add(new CacheHostBucket
{
Expand All @@ -89,16 +96,6 @@ public CacheClient()

// Now calculate the load balancing distribution
CalculateCacheHostLoadBalancingDistribution();

// Now connect to each cache host
for (int i = 0; i < _cacheHostLoadBalancingDistribution.Count; i++)
{
var cacheHostBucket = _cacheHostLoadBalancingDistribution[i];
if (!cacheHostBucket.CacheHost.Connect())
{
i--;
}
}
}

/// <summary>
Expand Down
16 changes: 7 additions & 9 deletions Dache.Client/CommunicationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ public CommunicationClient(string address, int port, int hostReconnectIntervalMi

public bool Connect()
{
return _client.Connect(_remoteEndPoint);
var result = _client.Connect(_remoteEndPoint);
if (!result)
{
// Disconnect the client
DisconnectFromServer();
}
return result;
}

/// <summary>
Expand Down Expand Up @@ -708,14 +714,6 @@ public override string ToString()
/// </summary>
public event EventHandler Reconnected;

private void HandleError(object state, SocketErrorArgs e)
{
// Enter the disconnected state
DisconnectFromServer();

throw new Exception(e.ErrorMessage);
}

/// <summary>
/// Makes the client enter the disconnected state.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions Dache.PerformanceTests/InfiniteAdd/InfiniteAddTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public static void Run()
Console.WriteLine("***** BEGIN INFINITE ADD TEST (WILL NEVER END) *****");
Console.WriteLine();

cacheClient.HostDisconnected += (sender, e) => { Console.WriteLine("*** Host disconnected"); };
cacheClient.HostReconnected += (sender, e) => { Console.WriteLine("*** Host reconnected"); };

int i = 1;
while (true)
{
Expand Down

0 comments on commit 297ff63

Please sign in to comment.