-
-
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?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
import io.sentry.util.AutoClosableReentrantLock; | ||
import io.sentry.util.Objects; | ||
import io.sentry.util.SpanUtils; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.ListIterator; | ||
import java.util.Map; | ||
|
@@ -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 commentThe 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 |
||
@NotNull final ListIterator<Span> iterator = this.children.listIterator(); | ||
while (iterator.hasNext()) { | ||
iterator.next(); | ||
} | ||
Comment on lines
+158
to
+160
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
while (iterator.hasPrevious()) { | ||
@NotNull final Span span = iterator.previous(); | ||
span.setSpanFinishedCallback(null); | ||
|
@@ -677,14 +679,13 @@ private void updateBaggageValues(final @NotNull Baggage baggage) { | |
} | ||
|
||
private boolean hasAllChildrenFinished() { | ||
final List<Span> spans = new ArrayList<>(this.children); | ||
if (!spans.isEmpty()) { | ||
for (final Span span : spans) { | ||
// This is used in the spanFinishCallback, when the span isn't finished, but has a finish | ||
// date | ||
if (!span.isFinished() && span.getFinishDate() == null) { | ||
return false; | ||
} | ||
@NotNull final ListIterator<Span> iterator = this.children.listIterator(); | ||
while (iterator.hasNext()) { | ||
@NotNull final Span span = iterator.previous(); | ||
// This is used in the spanFinishCallback, when the span isn't finished, but has a finish | ||
// date | ||
if (!span.isFinished() && span.getFinishDate() == null) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
|
@@ -909,12 +910,14 @@ public void setName(@NotNull String name, @NotNull TransactionNameSource transac | |
|
||
@Override | ||
public @Nullable ISpan getLatestActiveSpan() { | ||
final List<Span> spans = new ArrayList<>(this.children); | ||
if (!spans.isEmpty()) { | ||
for (int i = spans.size() - 1; i >= 0; i--) { | ||
if (!spans.get(i).isFinished()) { | ||
return spans.get(i); | ||
} | ||
@NotNull final ListIterator<Span> iterator = this.children.listIterator(); | ||
while (iterator.hasNext()) { | ||
iterator.next(); | ||
} | ||
while (iterator.hasPrevious()) { | ||
@NotNull final Span span = iterator.previous(); | ||
if (!span.isFinished()) { | ||
return span; | ||
} | ||
} | ||
return null; | ||
|
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