diff --git a/src/Microsoft.AspNetCore.Http.Connections/Internal/HttpConnectionContext.cs b/src/Microsoft.AspNetCore.Http.Connections/Internal/HttpConnectionContext.cs index 86d5292e0d..1e2b330860 100644 --- a/src/Microsoft.AspNetCore.Http.Connections/Internal/HttpConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Http.Connections/Internal/HttpConnectionContext.cs @@ -26,11 +26,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal IHttpContextFeature, IHttpTransportFeature { + private readonly object _itemsLock = new object(); private readonly object _heartbeatLock = new object(); private List<(Action handler, object state)> _heartbeatHandlers; private readonly ILogger _logger; private PipeWriterStream _applicationStream; private IDuplexPipe _application; + private IDictionary _items; // This tcs exists so that multiple calls to DisposeAsync all wait asynchronously // on the same task @@ -95,7 +97,24 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal public ClaimsPrincipal User { get; set; } - public override IDictionary Items { get; set; } = new ConnectionItems(new ConcurrentDictionary()); + public override IDictionary Items + { + get + { + if (_items == null) + { + lock (_itemsLock) + { + if (_items == null) + { + _items = new ConnectionItems(new ConcurrentDictionary()); + } + } + } + return _items; + } + set => _items = value ?? throw new ArgumentNullException(nameof(value)); + } public IDuplexPipe Application { diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs index 8c5096b319..384275bb29 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(TransportTypes))] public async Task CanStartAndStopConnectionUsingGivenTransport(HttpTransportType transportType) { - using (StartVerifableLog(out var loggerFactory)) + using (StartVerifableLog(out var loggerFactory, testName: $"CanStartAndStopConnectionUsingGivenTransport_{transportType}")) { var url = _serverFixture.Url + "/echo"; var connection = new HttpConnection(new Uri(url), transportType, loggerFactory);