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

Clear context propagation virtual field #12397

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ public static PropagatedContext enter(@Advice.Argument(1) SystemMessage systemMe

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(1) SystemMessage systemMessage,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<SystemMessage, PropagatedContext> virtualField =
VirtualField.find(SystemMessage.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(
propagatedContext, throwable, virtualField, systemMessage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ public static PropagatedContext enterDispatch(@Advice.Argument(1) Envelope envel

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitDispatch(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(1) Envelope envelope,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<Envelope, PropagatedContext> virtualField =
VirtualField.find(Envelope.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, envelope);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ public static PropagatedContext enterJobSubmit(@Advice.Argument(0) ForkJoinTask<

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitJobSubmit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(0) ForkJoinTask<?> task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ public static <T> PropagatedContext attachContextToTask(
* Clean up {@code propagatedContext} in case of any submission errors. Call this method after the
* submission method has exited.
*/
public static void cleanUpAfterSubmit(
@Nullable PropagatedContext propagatedContext, @Nullable Throwable throwable) {
public static <T> void cleanUpAfterSubmit(
@Nullable PropagatedContext propagatedContext,
@Nullable Throwable throwable,
VirtualField<T, PropagatedContext> virtualField,
T task) {
if (propagatedContext != null && throwable != null) {
/*
Note: this may potentially clear somebody else's parent span if we didn't set it
Expand All @@ -106,6 +109,7 @@ public static void cleanUpAfterSubmit(
exceptions.
*/
propagatedContext.clear();
virtualField.set(task, null);
Copy link
Member

Choose a reason for hiding this comment

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

maybe a comment here that this is only needed for cleaning up the fallback map?

or alternatively, do we want to just think of this as a "more correct" behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment. I think that with fallback map we need to do this, though ideally the fallback shouldn't be used at all which is what we really need to fix.

}
}

Expand All @@ -118,6 +122,7 @@ public static <T> void cleanPropagatedContext(

PropagatedContext propagatedContext = virtualField.get(task);
if (propagatedContext != null) {
virtualField.set(task, null);
propagatedContext.clear();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static <T> Scope makePropagatedContextCurrent(
VirtualField<T, PropagatedContext> virtualField, T task) {
PropagatedContext propagatedContext = virtualField.get(task);
if (propagatedContext != null) {
virtualField.set(task, null);
Context context = propagatedContext.getAndClear();
if (context != null) {
return context.makeCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ public static PropagatedContext enterJobSubmit(

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitJobSubmit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(0) Runnable task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<Runnable, PropagatedContext> virtualField =
VirtualField.find(Runnable.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}

Expand All @@ -126,8 +130,12 @@ public static PropagatedContext enterJobSubmit(@Advice.Argument(0) ForkJoinTask<

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitJobSubmit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(0) ForkJoinTask<?> task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}

Expand All @@ -148,6 +156,7 @@ public static PropagatedContext enterJobSubmit(

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitJobSubmit(
@Advice.Argument(0) Runnable task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable,
@Advice.Return Future<?> future) {
Expand All @@ -156,7 +165,9 @@ public static void exitJobSubmit(
VirtualField.find(Future.class, PropagatedContext.class);
virtualField.set(future, propagatedContext);
}
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
VirtualField<Runnable, PropagatedContext> virtualField =
VirtualField.find(Runnable.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}

Expand All @@ -176,6 +187,7 @@ public static PropagatedContext enterJobSubmit(@Advice.Argument(0) Callable<?> t

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitJobSubmit(
@Advice.Argument(0) Callable<?> task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable,
@Advice.Return Future<?> future) {
Expand All @@ -184,7 +196,9 @@ public static void exitJobSubmit(
VirtualField.find(Future.class, PropagatedContext.class);
virtualField.set(future, propagatedContext);
}
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
VirtualField<Callable<?>, PropagatedContext> virtualField =
VirtualField.find(Callable.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}

Expand Down Expand Up @@ -230,7 +244,8 @@ public static void submitExit(
VirtualField<Callable<?>, PropagatedContext> virtualField =
VirtualField.find(Callable.class, PropagatedContext.class);
PropagatedContext propagatedContext = virtualField.get(task);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
ExecutorAdviceHelper.cleanUpAfterSubmit(
propagatedContext, throwable, virtualField, task);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ public static PropagatedContext enterFork(@Advice.This ForkJoinTask<?> task) {

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitFork(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.This ForkJoinTask<?> task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ public static PropagatedContext enterCallableFork(@Advice.Argument(0) Callable<?

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitCallableFork(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(0) Callable<?> task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<Callable<?>, PropagatedContext> virtualField =
VirtualField.find(Callable.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ public static PropagatedContext addListenerEnter(@Advice.Argument(0) Runnable ta

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void addListenerExit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(0) Runnable task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<Runnable, PropagatedContext> virtualField =
VirtualField.find(Runnable.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ public static PropagatedContext enterJobSubmit(@Advice.Argument(0) Runnable task

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitJobSubmit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(0) Runnable task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<Runnable, PropagatedContext> virtualField =
VirtualField.find(Runnable.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ public static PropagatedContext onEnter(@Advice.Argument(0) Runnable call) {

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void onExit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(0) Runnable call,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<Runnable, PropagatedContext> virtualField =
VirtualField.find(Runnable.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, call);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ public static PropagatedContext onEnter(@Advice.Argument(0) Runnable call) {

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void onExit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(0) Runnable call,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<Runnable, PropagatedContext> virtualField =
VirtualField.find(Runnable.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, call);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ public static PropagatedContext enter(@Advice.Argument(1) SystemMessage systemMe

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(1) SystemMessage systemMessage,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<SystemMessage, PropagatedContext> virtualField =
VirtualField.find(SystemMessage.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(
propagatedContext, throwable, virtualField, systemMessage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ public static PropagatedContext enterDispatch(@Advice.Argument(1) Envelope envel

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitDispatch(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(1) Envelope envelope,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<Envelope, PropagatedContext> virtualField =
VirtualField.find(Envelope.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, envelope);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ public static PropagatedContext enterJobSubmit(@Advice.Argument(0) ForkJoinTask<

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitJobSubmit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(0) ForkJoinTask<?> task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ public static PropagatedContext enterJobSubmit(@Advice.Argument(0) Runnable task

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitJobSubmit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(0) Runnable task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<Runnable, PropagatedContext> virtualField =
VirtualField.find(Runnable.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ public static PropagatedContext enterJobSubmit(@Advice.Argument(1) Runnable task

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exitJobSubmit(
@Advice.Enter PropagatedContext propagatedContext, @Advice.Thrown Throwable throwable) {
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
@Advice.Argument(1) Runnable task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<Runnable, PropagatedContext> virtualField =
VirtualField.find(Runnable.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
}
}
}
Loading