-
Notifications
You must be signed in to change notification settings - Fork 158
Concurrency issue in HtmlSanitizer #519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
First up can I check a couple of things:
|
Sorry, can't answer that - that is rather difficult to verify.
Certainly an intermittent issue - the log indicates that there were three simultaneous requests to the website.
No.
Cofoundry: 0.9.1 (Nuget package number). Target framework is netcoreapp3.1. |
Looking into "mganss", there error is here: https://github.com/mganss/HtmlSanitizer/blob/master/src/HtmlSanitizer/HtmlSanitizer.cs#L638
Here Probably not something Cofoundry can do anything about - besides adding some locking statements. |
I don't see why there would be a concurrency issue with the HashSet unless it was being altered while the check was being made, and on a cursory look over the code I can't see how that might happen, given we create the mganss sanitizer and the ruleset on demand and have everything registered as transient. That's why I was thinking about un-awaited async calls in your views, as I wouldn't expect anything in a request to run concurrently anyway. Are you altering the sanitizer rulesets at all? There must be something somewhere, but I'm not seeing it as yet, I will probably have to do a deeper dive into the code. |
Now, I haven't experienced it myself with HashSet - but with Dictionary you cannot even have two concurrent readers! It is most likely the same with HashSet. So don't look for concurrent read/write - all you need is two concurrent reads on the same collection - and that is not difficult to imagine. |
For the code here (any code in fact) to be thread safe, you need to use the concurrent versions of the collections. You have to be quite unlucky to experience issues - but it does happen. |
The docs for Dictionary indicate that you can have two concurrent readers, but not if there are concurrent writes. The docs don't mention anything for HashSet, but my assumption would be the same - I'm not expecting the HashSet to be modified after it's been constructed, but looking at the error message that mentions "a concurrent update was performed...", it seems it must be. I'll need to do a deeper dive when i have some time, but can you let me know if you are you altering/customizing the sanitizer rulesets at all? |
Okay, I must have been mistaken somehow. Pretty sure that we had issues with reading a standard dictionary, but cannot reproduce it. I have not, consciously, done anything to modify the sanitizer rulesets. |
…urage immutability and help to avoid issues like #519.
As part of the v0.12 release there are improvements in both the mganss html sanaitizer and the Cofoundry implementation to improve the immutability of sanitizer configuration, which should illiminate the kinds of issues you are seeing. I wasn't able to replicate the issue though so feel free to reopen the issue if you're still having problems after the update. I will close this for now; the changed will be released with v0.12. |
I found this error in the Cofoundry error log - it seems like there is a concurrency issue in HtmlSanitizer.
Message: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
The text was updated successfully, but these errors were encountered: