You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Why do the frames not belong to its activity when Task.Yield() is involved? #2130
In an ASP.NET Core Web application, on the request of GET /weatherforecast, GetForecasts() will be called. However, in the trace, the GetForecasts() does not belong to the activity when putting behind Task.Yield() like this:
In the CallTree view, the frame is attribute to a IO ThreadPool Worker, but not any activity:
In comparison, only change a line of code, the result is more favorable:
{awaitTask.Delay(5);// Change from Task.Yield()returnWeatherForecastHelper.GetForecasts();})
Is this behavior expected? Can you help understand the difference?
Attaching the trace files:
Does not belong to an activity when using yield: Yield.zip
Does belong to an activity when using delay: Delay.zip
FWIW, I am trying this on ASP.NET Core 8.0 runtime, Windows, and it reproduced for both minimal API and controller based API.
Here are some details of the environment:
.NET SDK:
Version: 8.0.404
Commit: 7b190310f2
Workload version: 8.0.400-manifests.c6df56b6
MSBuild version: 17.11.9+a69bbaaf5
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.404\
I don't think the behavior is expected. As for where the issue is - probably one of two places:
Something in the TplEventSource didn't log an event it needed to log in order to correlate the code before/after the await Task.Yield()
Something in TraceEvent analysis of the events didn't work correctly to recognize the correlation.
Someone will need to dig into the traces to know more, potentially Mitchell Hwang (@mdh1418). We can investigate but likely not right away unless its urgent. Since the issue has been open for a few months guessing not urgent?
Activity
cincuranet commentedon Mar 12, 2025
Noah Falk (@noahfalk) Any ideas here?
noahfalk commentedon Mar 13, 2025
I don't think the behavior is expected. As for where the issue is - probably one of two places:
Someone will need to dig into the traces to know more, potentially Mitchell Hwang (@mdh1418). We can investigate but likely not right away unless its urgent. Since the issue has been open for a few months guessing not urgent?
xiaomi7732 commentedon Mar 13, 2025
Well, I don't think it is the end of world without it. However, are these opportunities missed correctly finding the perf issue? :-)