-
Notifications
You must be signed in to change notification settings - Fork 111
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
Fixes a bug that caused concurrent field access of cloned, read-only structs with more than 5 members to be non-deterministic. #630
Conversation
…structs with more than 5 members to be non-deterministic.
@Override | ||
public void makeReadOnly() { | ||
// Eagerly initialize the fields map to prevent potential data races https://github.com/amazon-ion/ion-java/issues/629 | ||
fieldMapIsActive(_child_count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name reads like a Boolean accessor.
@@ -261,6 +266,30 @@ public void modifyAfterCloneDoesNotChangeOriginal() { | |||
assertNotEquals(original, clone); | |||
} | |||
|
|||
@Test | |||
public void readOnlyIonStructMultithreadedTest() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion—It would be nice to have a more descriptive name.
@@ -101,6 +101,14 @@ private void build_field_map() | |||
_field_map.put(v._fieldName, ii); // this causes the map to have the largest index value stored | |||
} | |||
} | |||
|
|||
@Override | |||
public void makeReadOnly() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to only do this for IonStructLite
as opposed to IonContainerLite
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do what, specifically? The field map is contained in IonStructLite
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if eager initialization is needed for IonContainerLite
as well, but it seems the issue is isolated to IonStructLite
Codecov ReportAll modified and coverable lines are covered by tests ✅
... and 1 file with indirect coverage changes 📢 Thoughts on this report? Let us know!. |
Issue #, if available:
Closes #629
Description of changes:
The
build_field_map()
method assigns an empty map to the_fields_map
field, and then populates it. This can result in a race condition where the fields map is active (i.e. not null) before it is actually populated. This change ensures that the field map, if required, is initialized and populated before the struct is made read-only, making it available for concurrent access from multiple threads.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.