AngleSharp: `InvalidOperationException` due to failing `VerifyIntegrity`
Our Web Server code uses AngleSharp to do various HTML cleanup and Colourization. Today we start to get InvalidOperationExceptions on only 1 of our 6 servers From the stack trace, it looks like something might be missing some error handling.
Exception of type ‘System.InvalidOperationException’ was thrown.
at System.Runtime.CompilerServices.ConditionalWeakTable`2.VerifyIntegrity()
at System.Runtime.CompilerServices.ConditionalWeakTable`2.TryGetValue(TKey key, TValue& value)
at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key, CreateValueCallback createValueCallback)
at AngleSharp.Css.StyleAttributeObserver.AngleSharp.Dom.IAttributeObserver.NotifyChange(IElement host, String name, String value)
at AngleSharp.Dom.Element.SetupElement()
at AngleSharp.Html.Dom.HtmlImageElement.SetupElement()
at AngleSharp.Html.Parser.HtmlDomBuilder.CloseCurrentNode()
at AngleSharp.Html.Parser.HtmlDomBuilder.InBodyStartTagBreakrow(HtmlTagToken tag)
at AngleSharp.Html.Parser.HtmlDomBuilder.InBodyStartTag(HtmlTagToken tag)
at AngleSharp.Html.Parser.HtmlDomBuilder.Parse(HtmlParserOptions options)
at AngleSharp.Html.Parser.HtmlParser.Parse(HtmlDocument document)
at CodeProject.Modules.Articles.Article.get_FormattedContent()
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (17 by maintainers)
Commits related to this issue
- Removed the ConditionalWeakTable from ImportLinkRelation. See issue #918 — committed to matthewDDennis/AngleSharp by matthewDDennis 3 years ago
FYI, I’ve eliminated all code that could cause Thread Aborts and the issue has not been observed since.
I though you might be using the same value for multiple IDocuments based on the implementation of Document.Equals.
I’ve tracked down how the CWT is being corrupted.
When we load an Article for display, we use AngleSharp to format/sanitize the HTML content of the article if it hasn’t been cached recently. There are a few pages that load a lot of Articles, and under high load, these pages are timing out, usually in the formatting methods. When a page times out, it throws a ThreadAbortException, and because of where the code is executing there is a better chance than average of the exception being thrown while in the CWT code, causing the CWT corruption.
This may be causing issues in other libraries we are using, and I am investigating, Probably will need to write a Tip/Article about this.