-
-
Notifications
You must be signed in to change notification settings - Fork 449
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
Fix misuses of CopyOnWriteArrayList
#4247
base: main
Are you sure you want to change the base?
Conversation
@@ -155,7 +154,10 @@ private void onDeadlineTimeoutReached() { | |||
// abort all child-spans first, this ensures the transaction can be finished, | |||
// even if waitForChildren is true | |||
// iterate in reverse order to ensure leaf spans are processed before their parents | |||
@NotNull final ListIterator<Span> iterator = children.listIterator(children.size()); |
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 is not thread safe, the list could change size after we create the iterator
while (iterator.hasNext()) { | ||
iterator.next(); | ||
} |
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.
Need to do it this way as there's no other way to get a reverse iterator in a thread-safe manner
Performance metrics 🚀
|
SentryTracer.children
CopyOnWriteArrayList
Only found another occurrence where we are misusing |
return new CopyOnWriteArrayList<>(attachments); | ||
return attachments; |
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.
It is not necessary to copy here, as we are already using a CopyOnWriteArrayList
📜 Description
CopyOnWriteArrayList
allows us to access its elements without copying and without the possibility to cause aConcurrentModificationException
.This PR modifies its usages so that we avoid copying in order to get better performance memory-wise.
We also make sure that we are using it correctly to avoid other issues (using the iterator to avoid a possible NPE that could happen with index-based accesses, and other cases where we do things that are not thread safe).
💡 Motivation and Context
Closes #2815
💚 How did you test it?
Tested as documented in #2815 (comment)
📝 Checklist
sendDefaultPII
is enabled.