Merge pull request #10785 from umbraco/v9/bugfix/10699/swapped_hashset_to_concurrent_hashset

v9: Changed HashSet to ConcurrentHashSet to fix concurrency issues https://github.com/umbraco/Umbraco-CMS/issues/10699
This commit is contained in:
Bjarke Berg
2021-08-04 09:51:11 +02:00
committed by GitHub
2 changed files with 19 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
// See LICENSE for more details.
using System;
using System.Threading.Tasks;
using NUnit.Framework;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Tests.UnitTests.AutoFixture;
@@ -36,5 +37,15 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Website
Assert.AreEqual("~/Views/Template.cshtml", PathUtility.EnsurePathIsApplicationRootPrefixed("/Views/Template.cshtml"));
Assert.AreEqual("~/Views/Template.cshtml", PathUtility.EnsurePathIsApplicationRootPrefixed("~/Views/Template.cshtml"));
}
[AutoMoqData]
[Test]
public void EnsureApplicationMainUrl(AspNetCoreHostingEnvironment sut)
{
var url = new Uri("http://localhost:5000");
sut.EnsureApplicationMainUrl(url);
Assert.AreEqual(sut.ApplicationMainUrl, url);
}
}
}

View File

@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Collections;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Extensions;
@@ -13,7 +15,7 @@ namespace Umbraco.Cms.Web.Common.AspNetCore
{
public class AspNetCoreHostingEnvironment : IHostingEnvironment
{
private readonly ISet<Uri> _applicationUrls = new HashSet<Uri>();
private readonly ConcurrentHashSet<Uri> _applicationUrls = new ConcurrentHashSet<Uri>();
private readonly IServiceProvider _serviceProvider;
private readonly IOptionsMonitor<HostingSettings> _hostingSettings;
private readonly IOptionsMonitor<WebRoutingSettings> _webRoutingSettings;
@@ -168,6 +170,7 @@ namespace Umbraco.Cms.Web.Common.AspNetCore
// (this is a simplified version of what was in 7.x)
// note: should this be optional? is it expensive?
if (currentApplicationUrl is null)
{
return;
@@ -181,9 +184,10 @@ namespace Umbraco.Cms.Web.Common.AspNetCore
var change = !_applicationUrls.Contains(currentApplicationUrl);
if (change)
{
_applicationUrls.Add(currentApplicationUrl);
ApplicationMainUrl = currentApplicationUrl;
if (_applicationUrls.TryAdd(currentApplicationUrl))
{
ApplicationMainUrl = currentApplicationUrl;
}
}
}
}