Commit 664de5d3 authored by Marc Gravell's avatar Marc Gravell

Fix critical issue in connection fail (exception on worker)

parent 165bdc60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace StackExchange.Redis.Tests
{
[TestFixture]
public class Lists : TestBase
{
[Test]
public void Ranges()
{
using(var conn = Create())
{
var db = conn.GetDatabase();
RedisKey key = Me();
db.KeyDelete(key, CommandFlags.FireAndForget);
db.ListRightPush(key, "abcdefghijklmnopqrstuvwxyz".Select(x => (RedisValue)x.ToString()).ToArray());
Assert.AreEqual(26, db.ListLength(key));
Assert.AreEqual("abcdefghijklmnopqrstuvwxyz", string.Concat(db.ListRange(key)));
var last10 = db.ListRange(key, -10, -1);
Assert.AreEqual("qrstuvwxyz", string.Concat(last10));
db.ListTrim(key, 0, -11);
Assert.AreEqual(16, db.ListLength(key));
Assert.AreEqual("abcdefghijklmnop", string.Concat(db.ListRange(key)));
}
}
}
}
......@@ -69,6 +69,7 @@
<Compile Include="FloatingPoint.cs" />
<Compile Include="Keys.cs" />
<Compile Include="KeysAndValues.cs" />
<Compile Include="Lists.cs" />
<Compile Include="Locking.cs" />
<Compile Include="MultiMaster.cs" />
<Compile Include="Naming.cs" />
......
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
......@@ -64,7 +65,7 @@ private static readonly Message
private Stream netStream, outStream;
// things sent to this physical, but not yet received
Queue<Message> outstanding = new Queue<Message>();
private readonly Queue<Message> outstanding = new Queue<Message>();
private SocketToken socketToken;
......@@ -145,7 +146,7 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception
// stop anything new coming in...
bridge.Trace("Failed: " + failureType);
bridge.OnDisconnected(failureType, this);
if(Interlocked.CompareExchange(ref failureReported, 1, 0) == 0)
if (Interlocked.CompareExchange(ref failureReported, 1, 0) == 0)
{
try
{
......@@ -161,11 +162,11 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception
: new RedisConnectionException(failureType, message, innerException);
throw ex;
}
catch(Exception caught)
catch (Exception caught)
{
bridge.OnConnectionFailed(this, failureType, caught);
}
}
// cleanup
......@@ -182,7 +183,8 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception
}
// burn the socket
multiplexer.SocketManager.Shutdown(socketToken);
var socketManager = multiplexer.SocketManager;
if(socketManager != null) socketManager.Shutdown(socketToken);
}
public override string ToString()
......
......@@ -282,10 +282,17 @@ private static void ProcessItems(Dictionary<IntPtr, SocketPair> socketLookup, Qu
#if VERBOSE
var watch = Stopwatch.StartNew();
#endif
switch (operation)
try
{
case CallbackOperation.Read: callback.Read(); break;
case CallbackOperation.Error: callback.Error(); break;
switch (operation)
{
case CallbackOperation.Read: callback.Read(); break;
case CallbackOperation.Error: callback.Error(); break;
}
}
catch (Exception ex)
{
Trace.WriteLine(ex);
}
#if VERBOSE
watch.Stop();
......@@ -340,7 +347,11 @@ private void EndConnect(IAsyncResult ar)
{
if (tuple != null)
{
tuple.Item2.Error();
try { tuple.Item2.Error(); }
catch (Exception ex)
{
Trace.WriteLine(ex);
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment