Skip to content
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

Bug in VersionSpecificWorkerContextWrapper.allStructureDefinitions() #6661

Open
Boereck opened this issue Jan 29, 2025 · 0 comments
Open

Bug in VersionSpecificWorkerContextWrapper.allStructureDefinitions() #6661

Boereck opened this issue Jan 29, 2025 · 0 comments

Comments

@Boereck
Copy link
Contributor

Boereck commented Jan 29, 2025

Describe the bug
The following code on the current (at the time of writing) master:

retVal = allStructureDefinitions.stream()
.map(myVersionCanonicalizer::structureDefinitionToCanonical)
.collect(Collectors.toList());
myAllStructures = retVal;
try {
for (IBaseResource next : allStructureDefinitions) {
Resource converted = convertToCanonicalVersionAndGenerateSnapshot(next, false);
retVal.add((StructureDefinition) converted);
}
myAllStructures = retVal;
} catch (Exception e) {
ourLog.error("Failure during snapshot generation", e);
myAllStructures = null;
}

Starting from the try block, the cached StructureDefinitions are snapshotted. However, instead of creating a new List for the resulting snapshotted StructureDefinitions, the resulting Resources are added to the list of previously fetched and converted StructureDefinitions. I am sure this is not correct, because both the non-snapshotted and the snapshotted version are stored to the same list.

In addition to that, the issue causes ConcurrentModificationExceptions, since the List being modified in the try block was stored to the myAllStructures field before. When a second thread calls allStructureDefinitions, before the first one enters the try block, it will get the list and can read it, while the first thread adds elements to that list.

However, this issue is easy to fix: Before entering the try, add the line

retVal = new ArrayList<>();`

@fil512 it seems this was introduced in commit 362dc09 by you. At least you are attributed as the author. Maybe you want to fix the issue, since this is a pretty trivial fix, I can open a PR as well, if this is preferred.

To Reproduce
Steps to reproduce the behavior:
Validate several resources in parallel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant