[APIPUB-114] - Make knownUnremediatedRequests a ConcurrentDictionary#138
Open
ea-mtenhoor wants to merge 1 commit into
Open
[APIPUB-114] - Make knownUnremediatedRequests a ConcurrentDictionary#138ea-mtenhoor wants to merge 1 commit into
ea-mtenhoor wants to merge 1 commit into
Conversation
Test Results180 tests 180 ✅ 6s ⏱️ Results for commit bb08dc1. |
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.
In API Publisher 1.3.0, if
--maxDegreeOfParallelismForPostResourceItemis greater than 1 and a remediation script is specified with--remediationsScriptFile, a non-concurrent collection error will occur when a POST error occurs that is not handled by the remediation script. The code in this PR resolves the error by changingknownUnremediatedRequestsfromHashSettoConcurrentDictionary.Explanation from Cursor:
What’s failing
knownUnremediatedRequestsis a normalHashSet<>, which is not safe for use from multiple threads at the same time.PostResourceProcessingBlocksFactory.cs
Lines 77-77
That same instance is passed into every
HandlePostItemMessagecall. The block that runs that method is configured with parallelism:PostResourceProcessingBlocksFactory.cs
Lines 102-112
So whenever
MaxDegreeOfParallelismForPostResourceItemis greater than 1, several posts can run at once. Polly’s retry delegate can then run on different logical threads and both:Add(line 200), andContainsinsideMayHaveRemediation(line 464),can touch the
HashSetconcurrently. That matches the exception: “Operations that change non-concurrent collections must have exclusive access.”The stack trace often lands on
Addbecause that’s a mutating operation;Containsconcurrent withAddis also undefined forHashSetand can corrupt internal state.Log message: