Bug Report
Prerequisites
For more information, see the CONTRIBUTING guide.
Description
Running OpenAsync concurrently leads to exception because of thread-unsafe collections inside CreatorCache
Steps to Reproduce
[Test]
public void CustomEventConstructedConcurrently()
{
var ctx1 = BrowsingContext.New(Configuration.Default.WithJs());
var ctx2 = BrowsingContext.New(Configuration.Default.WithJs());
var html = "<!doctype html><div id=result></div><script>var ev = new CustomEvent('foo'); document.querySelector('#result').textContent = ev.type;</script>";
Parallel.Invoke(() => Assert(ctx1), () => Assert(ctx2));
return;
void Assert(IBrowsingContext context) => Task
.Run(async () =>
{
var document = await context.OpenAsync(m => m.Content(html));
var result = document.QuerySelector("#result").TextContent;
NUnit.Framework.Assert.AreEqual("foo", result);
})
.Wait();
}
Possible Solution
Replace each Dictionary in CreatorCache with a ConcurrentDictionary
Bug Report
Prerequisites
AngleSharp.Cssfor CSS support)For more information, see the
CONTRIBUTINGguide.Description
Running
OpenAsyncconcurrently leads to exception because of thread-unsafe collections insideCreatorCacheSteps to Reproduce
Possible Solution
Replace each Dictionary in CreatorCache with a ConcurrentDictionary