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 @@ ...@@ -69,6 +69,7 @@
<Compile Include="FloatingPoint.cs" /> <Compile Include="FloatingPoint.cs" />
<Compile Include="Keys.cs" /> <Compile Include="Keys.cs" />
<Compile Include="KeysAndValues.cs" /> <Compile Include="KeysAndValues.cs" />
<Compile Include="Lists.cs" />
<Compile Include="Locking.cs" /> <Compile Include="Locking.cs" />
<Compile Include="MultiMaster.cs" /> <Compile Include="MultiMaster.cs" />
<Compile Include="Naming.cs" /> <Compile Include="Naming.cs" />
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
...@@ -64,7 +65,7 @@ private static readonly Message ...@@ -64,7 +65,7 @@ private static readonly Message
private Stream netStream, outStream; private Stream netStream, outStream;
// things sent to this physical, but not yet received // 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; private SocketToken socketToken;
...@@ -145,7 +146,7 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception ...@@ -145,7 +146,7 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception
// stop anything new coming in... // stop anything new coming in...
bridge.Trace("Failed: " + failureType); bridge.Trace("Failed: " + failureType);
bridge.OnDisconnected(failureType, this); bridge.OnDisconnected(failureType, this);
if(Interlocked.CompareExchange(ref failureReported, 1, 0) == 0) if (Interlocked.CompareExchange(ref failureReported, 1, 0) == 0)
{ {
try try
{ {
...@@ -161,7 +162,7 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception ...@@ -161,7 +162,7 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception
: new RedisConnectionException(failureType, message, innerException); : new RedisConnectionException(failureType, message, innerException);
throw ex; throw ex;
} }
catch(Exception caught) catch (Exception caught)
{ {
bridge.OnConnectionFailed(this, failureType, caught); bridge.OnConnectionFailed(this, failureType, caught);
} }
...@@ -182,7 +183,8 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception ...@@ -182,7 +183,8 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception
} }
// burn the socket // burn the socket
multiplexer.SocketManager.Shutdown(socketToken); var socketManager = multiplexer.SocketManager;
if(socketManager != null) socketManager.Shutdown(socketToken);
} }
public override string ToString() public override string ToString()
......
...@@ -282,11 +282,18 @@ private static void ProcessItems(Dictionary<IntPtr, SocketPair> socketLookup, Qu ...@@ -282,11 +282,18 @@ private static void ProcessItems(Dictionary<IntPtr, SocketPair> socketLookup, Qu
#if VERBOSE #if VERBOSE
var watch = Stopwatch.StartNew(); var watch = Stopwatch.StartNew();
#endif #endif
try
{
switch (operation) switch (operation)
{ {
case CallbackOperation.Read: callback.Read(); break; case CallbackOperation.Read: callback.Read(); break;
case CallbackOperation.Error: callback.Error(); break; case CallbackOperation.Error: callback.Error(); break;
} }
}
catch (Exception ex)
{
Trace.WriteLine(ex);
}
#if VERBOSE #if VERBOSE
watch.Stop(); watch.Stop();
ConnectionMultiplexer.TraceWithoutContext(string.Format("{0}: {1}ms on {2}", operation, watch.ElapsedMilliseconds, callback)); ConnectionMultiplexer.TraceWithoutContext(string.Format("{0}: {1}ms on {2}", operation, watch.ElapsedMilliseconds, callback));
...@@ -340,7 +347,11 @@ private void EndConnect(IAsyncResult ar) ...@@ -340,7 +347,11 @@ private void EndConnect(IAsyncResult ar)
{ {
if (tuple != null) 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