Commit 0e428a7c authored by Marc Gravell's avatar Marc Gravell Committed by Nick Craver

make sure there is only **one** path that can cause endpoints to be added, and...

make sure there is only **one** path that can cause endpoints to be added, and ensure that the activation happens after the constructor - removes race condition that can lead to abandoned endpoints; note as part of this, switch the server-snapshot to span-based
parent 97d9e375
...@@ -104,7 +104,7 @@ internal static string GetInnerMostExceptionMessage(Exception e) ...@@ -104,7 +104,7 @@ internal static string GetInnerMostExceptionMessage(Exception e)
} }
} }
internal static Exception NoConnectionAvailable(bool includeDetail, bool includePerformanceCounters, RedisCommand command, Message message, ServerEndPoint server, ServerEndPoint[] serverSnapshot) internal static Exception NoConnectionAvailable(bool includeDetail, bool includePerformanceCounters, RedisCommand command, Message message, ServerEndPoint server, ReadOnlySpan<ServerEndPoint> serverSnapshot)
{ {
string commandLabel = GetLabel(includeDetail, command, message); string commandLabel = GetLabel(includeDetail, command, message);
...@@ -138,7 +138,7 @@ internal static Exception NoConnectionAvailable(bool includeDetail, bool include ...@@ -138,7 +138,7 @@ internal static Exception NoConnectionAvailable(bool includeDetail, bool include
return ex; return ex;
} }
internal static Exception PopulateInnerExceptions(ServerEndPoint[] serverSnapshot) internal static Exception PopulateInnerExceptions(ReadOnlySpan<ServerEndPoint> serverSnapshot)
{ {
var innerExceptions = new List<Exception>(); var innerExceptions = new List<Exception>();
if (serverSnapshot != null) if (serverSnapshot != null)
......
...@@ -53,7 +53,6 @@ public ServerEndPoint(ConnectionMultiplexer multiplexer, EndPoint endpoint, Text ...@@ -53,7 +53,6 @@ public ServerEndPoint(ConnectionMultiplexer multiplexer, EndPoint endpoint, Text
isSlave = false; isSlave = false;
databases = 0; databases = 0;
writeEverySeconds = config.KeepAlive > 0 ? config.KeepAlive : 60; writeEverySeconds = config.KeepAlive > 0 ? config.KeepAlive : 60;
interactive = CreateBridge(ConnectionType.Interactive, log);
serverType = ServerType.Standalone; serverType = ServerType.Standalone;
// overrides for twemproxy // overrides for twemproxy
...@@ -635,7 +634,6 @@ internal void WriteDirectOrQueueFireAndForget<T>(PhysicalConnection connection, ...@@ -635,7 +634,6 @@ internal void WriteDirectOrQueueFireAndForget<T>(PhysicalConnection connection,
} }
} }
} }
private PhysicalBridge CreateBridge(ConnectionType type, TextWriter log) private PhysicalBridge CreateBridge(ConnectionType type, TextWriter log)
{ {
Multiplexer.Trace(type.ToString()); Multiplexer.Trace(type.ToString());
......
...@@ -163,11 +163,11 @@ internal async void BeginConnectAsync(EndPoint endpoint, Socket socket, Physical ...@@ -163,11 +163,11 @@ internal async void BeginConnectAsync(EndPoint endpoint, Socket socket, Physical
try try
{ {
if (socket.ConnectAsync(args)) if (socket.ConnectAsync(args))
{ { // asynchronous operation is pending
ConfigureTimeout(args, multiplexer.RawConfig.ConnectTimeout); ConfigureTimeout(args, multiplexer.RawConfig.ConnectTimeout);
} }
else else
{ { // completed synchronously
SocketAwaitable.OnCompleted(args); SocketAwaitable.OnCompleted(args);
} }
...@@ -177,7 +177,8 @@ internal async void BeginConnectAsync(EndPoint endpoint, Socket socket, Physical ...@@ -177,7 +177,8 @@ internal async void BeginConnectAsync(EndPoint endpoint, Socket socket, Physical
bool ignoreConnect = false; bool ignoreConnect = false;
ShouldIgnoreConnect(physicalConnection, ref ignoreConnect); ShouldIgnoreConnect(physicalConnection, ref ignoreConnect);
if (ignoreConnect) return; if (ignoreConnect) return;
await awaitable;
await awaitable; // wait for the connect to complete or fail (will throw)
switch (physicalConnection == null ? SocketMode.Abort : await physicalConnection.ConnectedAsync(socket, log, this).ForAwait()) switch (physicalConnection == null ? SocketMode.Abort : await physicalConnection.ConnectedAsync(socket, log, this).ForAwait())
{ {
......
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