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

Attempt to fix reference counting issues in ES client instrumentation #3256

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
[float]
===== Bug fixes
* Fixed SQS NoClassDefFoundError in AWS SDK instrumentation - {pull}3254[#3254]
* Fixed reference counting issues in elasticsearch instrumentation - {pull}3256[#3256]

[[release-notes-1.x]]
=== Java Agent version 1.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ ResponseListenerWrapper withClientSpan(ResponseListener delegate, Span<?> span)
// Order is important due to visibility - write to span last on this (initiating) thread
this.delegate = delegate;
this.isClientSpan = true;
this.context = span;
setContext(span);
return this;
}

ResponseListenerWrapper withContextPropagation(ResponseListener delegate, AbstractSpan<?> context) {
// Order is important due to visibility - write to span last on this (initiating) thread
this.delegate = delegate;
this.isClientSpan = false;
this.context = context;
setContext(context);
return this;
}

Expand Down Expand Up @@ -149,10 +149,20 @@ private void finishClientSpan(@Nullable Response response, @Nullable Throwable t
}
}

private void setContext(@Nullable AbstractSpan<?> newContext) {
if (newContext != null) {
newContext.incrementReferences();
}
if (context != null) {
context.decrementReferences();
}
context = newContext;
}

@Override
public void resetState() {
delegate = null;
context = null;
setContext(null);
isClientSpan = false;
}
}
Loading