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

Make access to ArrayDeque synchronized #7027

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Mahoney
Copy link

@Mahoney Mahoney commented Jan 16, 2025

ArrayDeque specifies that:

Array deques ... are not thread-safe; in the absence of external
synchronization, they do not support concurrent access by multiple
threads.

marshalerPool is concurrently added to by the OkHttp threadpool without synchronization, along with all threads that end spans (with synchronisation in SimpleSpanProcessor.exportLock, which is not used to synchronize with the OkHttp threadpool).

Just making the ArrayQueue synchronous internally removes all need to worry about upstream locks.

Fixes #7019

@Mahoney Mahoney requested a review from a team as a code owner January 16, 2025 14:27
Copy link

linux-foundation-easycla bot commented Jan 16, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Mahoney / name: Robert Elliot (6d32714)

ArrayDeque specifies that:

> Array deques ... are not thread-safe; in the absence of external
> synchronization, they do not support concurrent access by multiple
> threads.

`marshalerPool` is concurrently added to by the OkHttp threadpool
without synchronization, along with all threads that end spans (with
synchronisation in `SimpleSpanProcessor.exportLock`, which is not used
to synchronize with the OkHttp threadpool).

Just making the ArrayQueue synchronous internally removes all need to
worry about upstream locks.

Fixes open-telemetry#7019
@Mahoney Mahoney force-pushed the fix-concurrent-SpanReusableDataMarshaler branch from df49e28 to 6d32714 Compare January 16, 2025 14:39
Copy link

codecov bot commented Jan 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.95%. Comparing base (c8da020) to head (6d32714).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #7027   +/-   ##
=========================================
  Coverage     89.95%   89.95%           
  Complexity     6636     6636           
=========================================
  Files           745      745           
  Lines         20010    20015    +5     
  Branches       1962     1962           
=========================================
+ Hits          17999    18004    +5     
  Misses         1415     1415           
  Partials        596      596           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -20,7 +20,8 @@
*/
public class SpanReusableDataMarshaler {

private final Deque<LowAllocationTraceRequestMarshaler> marshalerPool = new ArrayDeque<>();
private final SynchronizedQueue<LowAllocationTraceRequestMarshaler> marshalerPool =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same construct is also used in

private final Deque<LowAllocationLogsRequestMarshaler> marshalerPool = new ArrayDeque<>();
and
private final Deque<LowAllocationMetricsRequestMarshaler> marshalerPool = new ArrayDeque<>();

did you consider just using a different queue implementation such as ConcurrentLinkedDeque?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this.

Also, this change is applicable to MetricReusableDataMarshaler and LogReusableDataMarshaler as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you consider just using a different queue implementation such as ConcurrentLinkedDeque?

No, I didn't even remember ConcurrentLinkedDeque existed, and I'm not familiar with its guarantees and performance characteristics. Might well be a better and lighter option.

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

Successfully merging this pull request may close these issues.

ArrayIndexOutOfBoundsException in ArrayDeque.add in GrpcExporter
3 participants