From 40ecc9df4de4bfc7394b99401e3bcb406f9debc7 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 1 Oct 2016 03:53:00 -0700 Subject: [PATCH] Remove GetOrAdd from AddNewConnection --- .../ConnectionManager.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNetCore.Sockets/ConnectionManager.cs b/src/Microsoft.AspNetCore.Sockets/ConnectionManager.cs index 5b97e63fad..182e330f0d 100644 --- a/src/Microsoft.AspNetCore.Sockets/ConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Sockets/ConnectionManager.cs @@ -39,21 +39,18 @@ namespace Microsoft.AspNetCore.Sockets { string id = MakeNewConnectionId(); - var state = _connections.GetOrAdd(id, connectionId => new ConnectionState()); - - // If there's no connection object then it's a new connection - if (state.Connection == null) + var state = new ConnectionState { - state.Connection = new Connection + Connection = new Connection { Channel = channel, ConnectionId = id - }; - } + }, + LastSeen = DateTimeOffset.UtcNow, + Active = true + }; - // Update the last seen and mark the connection as active - state.LastSeen = DateTimeOffset.UtcNow; - state.Active = true; + _connections.TryAdd(id, state); return state; }