Repository navigation
Conversation
Author
|
@dotnet-policy-service agree |
ReubenBond
approved these changes
Oct 31, 2026
ReubenBond
enabled auto-merge
October 31, 2026 01:02
auto-merge was automatically disabled
October 31, 2026 06:12
Head branch was pushed to by a user without write access
KoakiMiku
force-pushed
the
fix-task-log
branch
from
November 5, 2026 14:40
b64e5fa to
0664042
Compare
…uler when a structured logger serializes the `Task` argument (dotnet#11621)
KoakiMiku
force-pushed
the
fix-task-log
branch
from
November 5, 2026 14:40
0664042 to
164d72b
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11621
Problem
WorkItemGrouppasses liveTaskinstances as[LoggerMessage]arguments: the long-running turnwarning logs
task.AsyncState ?? task, and the DEBUG-only trace messages logtaskdirectly.A provider that serializes structured parameters by reflection — for example NLog
JsonLayoutwithIncludeEventProperties=true— enumerates the object's public properties.Task<T>exposesResult,and reading
Resulton an incomplete task blocks inTask.InternalWait/Monitor.Wait.The warning is written inline in
Execute'sfinallyblock on the activation's scheduler thread,before
_currentTask = null. When the log call blocks there, the thread never returns: theactivation stops consuming its queue,
NonReentrancyQueueSizegrows, every call to that activationtimes out, and
MaxRequestProcessingTimecannot recover it because no request is marked asexecuting.
The captured stack confirms the path:
Change
Every
Task-typed[LoggerMessage]parameter inWorkItemGroupbecomes astring, and each callsite passes
task.ToString():LogWarningLongRunningTurnkeeps its existing argument expression:task.AsyncState ?? taskisnow rendered with
.ToString(), so the warning still reports the async state object when one isset, and the task otherwise.
LogTraceEnqueueWorkItem,LogTraceAddToRunQueueandLogTraceAboutToExecuteTaskmessages do the same for
task.Message templates, event IDs and log levels are unchanged; only the parameter types change
(
object/Tasktostring). There is no behavioral change to scheduling, and no public API change.Rationale
ToString()of the sameobject as before, and text-based layouts (simple console, NLog
${message}) already renderedparameters through
ToString().Taskdoes not overrideToString()(checked on .NET 8 and.NET 10), so that text is the runtime type name; for an async turn it is the async state machine
type, which still identifies the async method.
Task.Result. The arguments are plain strings, so a reflection-basedserializer has nothing to introspect.
(the trace messages) or already decided to emit the warning (turn duration above
TurnWarningLengthThreshold).Structured sinks now record a string instead of an object graph for these parameters. That object
graph was exactly what could deadlock the scheduler.
Microsoft Reviewers: Open in CodeFlow