Commit 41526630 authored by Nick Craver's avatar Nick Craver

Fix Internetwork defualt case for localhost

If we're AddressFamily.Unspecified, that'll always error. Assume IPv4 (as we did before).
parent d9b09fc4
...@@ -14,14 +14,17 @@ public void ParseEndpoints() ...@@ -14,14 +14,17 @@ public void ParseEndpoints()
var eps = new EndPointCollection var eps = new EndPointCollection
{ {
{ "127.0.0.1", 1000 }, { "127.0.0.1", 1000 },
{ "::1", 1001 } { "::1", 1001 },
{ "localhost", 1002 }
}; };
Assert.Equal(AddressFamily.InterNetwork, eps[0].AddressFamily); Assert.Equal(AddressFamily.InterNetwork, eps[0].AddressFamily);
Assert.Equal(AddressFamily.InterNetworkV6, eps[1].AddressFamily); Assert.Equal(AddressFamily.InterNetworkV6, eps[1].AddressFamily);
Assert.Equal(AddressFamily.Unspecified, eps[2].AddressFamily);
Assert.Equal("127.0.0.1:1000", eps[0].ToString()); Assert.Equal("127.0.0.1:1000", eps[0].ToString());
Assert.Equal("[::1]:1001", eps[1].ToString()); Assert.Equal("[::1]:1001", eps[1].ToString());
Assert.Equal("Unspecified/localhost:1002", eps[2].ToString());
} }
[Fact] [Fact]
......
using System; using System.Threading;
using System.IO;
using System.Threading;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
namespace StackExchange.Redis.Tests namespace StackExchange.Redis.Tests
{ {
public class RealWorld public class RealWorld : TestBase
{ {
public ITestOutputHelper Output { get; } public RealWorld(ITestOutputHelper output) : base(output) { }
public RealWorld(ITestOutputHelper output) => Output = output;
[Fact] [Fact]
public void WhyDoesThisNotWork() public void WhyDoesThisNotWork()
{ {
var sw = new StringWriter();
Output.WriteLine("first:"); Output.WriteLine("first:");
using (var conn = ConnectionMultiplexer.Connect("localhost:6379,localhost:6380,name=Core (Q&A),tiebreaker=:RedisMaster,abortConnect=False", sw)) var config = ConfigurationOptions.Parse("localhost:6379,localhost:6380,name=Core (Q&A),tiebreaker=:RedisMaster,abortConnect=False");
Assert.Equal(2, config.EndPoints.Count);
Output.WriteLine("Endpoint 0: {0} (AddressFamily: {1})", config.EndPoints[0], config.EndPoints[0].AddressFamily);
Output.WriteLine("Endpoint 1: {0} (AddressFamily: {1})", config.EndPoints[1], config.EndPoints[1].AddressFamily);
using (var conn = ConnectionMultiplexer.Connect("localhost:6379,localhost:6380,name=Core (Q&A),tiebreaker=:RedisMaster,abortConnect=False", Writer))
{ {
Output.WriteLine(sw.ToString());
Output.WriteLine(""); Output.WriteLine("");
Output.WriteLine("pausing..."); Output.WriteLine("pausing...");
Thread.Sleep(200); Thread.Sleep(200);
Output.WriteLine("second:"); Output.WriteLine("second:");
sw = new StringWriter(); bool result = conn.Configure(Writer);
bool result = conn.Configure(sw);
Output.WriteLine("Returned: {0}", result); Output.WriteLine("Returned: {0}", result);
Output.WriteLine(sw.ToString());
} }
} }
} }
......
...@@ -141,7 +141,7 @@ public SocketManager(string name, bool useHighPrioritySocketThreads) ...@@ -141,7 +141,7 @@ public SocketManager(string name, bool useHighPrioritySocketThreads)
dedicatedWriter.Priority = useHighPrioritySocketThreads ? ThreadPriority.AboveNormal : ThreadPriority.Normal; dedicatedWriter.Priority = useHighPrioritySocketThreads ? ThreadPriority.AboveNormal : ThreadPriority.Normal;
#else #else
Thread dedicatedWriter = new Thread(writeAllQueues); Thread dedicatedWriter = new Thread(writeAllQueues);
#endif #endif
dedicatedWriter.Name = name + ":Write"; dedicatedWriter.Name = name + ":Write";
dedicatedWriter.IsBackground = true; // should not keep process alive dedicatedWriter.IsBackground = true; // should not keep process alive
dedicatedWriter.Start(this); // will self-exit when disposed dedicatedWriter.Start(this); // will self-exit when disposed
...@@ -174,7 +174,8 @@ public void Dispose() ...@@ -174,7 +174,8 @@ public void Dispose()
internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log) internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log)
{ {
var socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); var addressFamily = endpoint.AddressFamily == AddressFamily.Unspecified ? AddressFamily.InterNetwork : endpoint.AddressFamily;
var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp);
SetFastLoopbackOption(socket); SetFastLoopbackOption(socket);
socket.NoDelay = true; socket.NoDelay = true;
try try
......
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