From a73c2c7a0c2bedf51cedd347387a170d3abdb274 Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Wed, 8 Jan 2025 17:30:23 +0000 Subject: [PATCH] Don't reuse a ValueTask --- .../CallTarget/Handlers/Continuations/ValueTaskActivator`1.cs | 2 ++ .../Continuations/ValueTaskContinuationGenerator`1.NetFx.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/Handlers/Continuations/ValueTaskActivator`1.cs b/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/Handlers/Continuations/ValueTaskActivator`1.cs index 125dbbfa0dd1..fdb9c2cd503a 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/Handlers/Continuations/ValueTaskActivator`1.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/Handlers/Continuations/ValueTaskActivator`1.cs @@ -90,5 +90,7 @@ internal static TValueTask FallbackResultActivator(TResult task) => (TValueTask)Activator.CreateInstance(typeof(TValueTask), task)!; public static TValueTask CreateInstance(Task task) => TaskActivator(task); + + public static TValueTask CreateInstance(TResult result) => ResultActivator(result); } #endif diff --git a/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/Handlers/Continuations/ValueTaskContinuationGenerator`1.NetFx.cs b/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/Handlers/Continuations/ValueTaskContinuationGenerator`1.NetFx.cs index f77b3c75effa..063c6dd86770 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/Handlers/Continuations/ValueTaskContinuationGenerator`1.NetFx.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/CallTarget/Handlers/Continuations/ValueTaskContinuationGenerator`1.NetFx.cs @@ -80,7 +80,7 @@ public SyncCallbackHandler(ContinuationMethodDelegate continuation, bool preserv // ok all good, just run synchronously var unwrappedResult = previousValueTask.Result; _continuation(instance, unwrappedResult, exception, in state); - return returnValue; + return ValueTaskActivator.CreateInstance(unwrappedResult); } // uh oh, need to extract the task, await it, run the continuation