Repository navigation
Lock the shared sets of the parallel STEP import - #499
Merged
Merged
Conversation
With StepImport.Parallel, CreateEntity runs on several threads, but it added mapped items to the HashSet mappedItems and, for assemblies, products to the HashSet products without a lock (the other place that adds products locks it). Concurrent Add calls can corrupt a HashSet, and the enumeration of mappedItems after the creation then met a null entry: a NullReferenceException in ImportStep.Read. StepCyclicReferenceTest from #498 imports a file with mapped items 20 times in parallel and showed this now and then on the 2-core CI runner. With the test process limited to 2 cores, it failed 3 of 30 times without this change and 0 of 60 times with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YXvDW91oXpy7RquGHNxgR5
Merged
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.
Fixes an intermittent failure of
StepCyclicReferenceTest.import_step_with_representations_that_map_each_other, a test from #498. The test failed now and then on the 2-core CI runner, on #468 and #472 so far:Cause
With
StepImport.Parallel,CreateEntityruns on several threads. Two places in it added to a sharedHashSet<Item>without a lock:mappedItems.Add(item)for everyMAPPED_ITEM;products.Add(relatingProduct)for assemblies. The other place that adds products already useslock (products).Concurrent
Addcalls can corrupt aHashSet. WhenReadlater enumeratesmappedItems(line 1683), it meets anullentry. The bug is older than #498. The new test makes it visible, because it imports a file with mapped items 20 times in parallel.Fix
Both
Addcalls now run under a lock on their set, as the existinglock (products)does.Verification
I limited the test process to 2 cores with
taskset -c 0,1, as on the runner:CADability.ImportTestson Linux: 85 passed, 5 skipped, 0 failed.Not covered here
The assembly branch of the parallel import changes other shared state without a lock: the
parameterdictionary of a product ("_children") and the list of its children. That is a separate, pre-existing issue, and no test shows it, so this PR leaves it as it is.Generated by Claude Code