Make hash caches thread-safe, Netkan warning for uncompiled plugins#4400
Merged
Conversation
Pull Request Test Coverage Report for Build 15888219272Details
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Inflator has been emitting
Index was outside the bounds of the array.errors for a while now, which cannot be reproduced locally. After #4398, we captured the full stack trace:The
Dictionary.TryInsertcall in question must be inNetFileCache.GetFileHash:CKAN/Core/Net/NetFileCache.cs
Lines 649 to 682 in dd37ee2
Later, that stack trace was replaced by one featuring
AggregateException, which I have been trying to purge from our logs.Causes
Dictionary.Addis thread unsafe and can throw this exception when multiple threads use it concurrently.https://stackoverflow.com/questions/15095817/adding-to-a-generic-dictionary-causes-indexoutofrangeexception
AggregateExceptiononly worked when there was a singleInnerException; if it contained multiple in theInnerExceptionsproperty, it wasn't caught.Motivation
Twice in the past few weeks, we have had mods submitted by someone other than their primary C# coder, who didn't compile the plugin (see KSP-CKAN/NetKAN#10592 and KSP-CKAN/NetKAN#10600). If this is going to be a common pattern going forward, it would be good to detect it programmatically rather than making me dig through the ZIP file and repo to notice it.
Changes
NetFileCacheis updated to useConcurrentDictionaryfor those caches, which will not throwIndexOutOfRangExceptionwhen trying to add an element.GUI.Mainis excluded from coverage because it is aFormwhich we will not instantiate in tests.CKAN.Extensions.ExceptionExtensions.RethrowInneris created to wrap the more complex logic needed to pick the first element fromInnerExceptionsand rethrow it, and called by all the places where we catchAggregateException.*.cs,*.csproj, or*.slnfiles in a ZIP and doesn't see a*.dll, a warning is emitted, to make this problem easier to spot.