Skip to content

Conversation

stephentoub
Copy link
Member

If Task.Start and Task.Wait are used concurrently, it's possible for Wait to execute the task as part of the inlining logic, causing the task's completion logic to null out its m_action during the call to Start. This isn't generally a functional issue, as synchronization ensures it's only ever invoked once, however EventSource-based tracing code may try to extract the method name from the delegate, and it can end up hitting an ArgumentNullException due to the race causing the delegate to be null.

Fixes #119484

If Task.Start and Task.Wait are used concurrently, it's possible for Wait to execute the task as part of the inlining logic, causing the task's completion logic to null out its m_action during the call to Start. This isn't generally a functional issue, as synchronization ensures it's only ever invoked once, however EventSource-based tracing code may try to extract the method name from the delegate, and it can end up hitting an ArgumentNullException due to the race causing the delegate to be null.
@Copilot Copilot AI review requested due to automatic review settings September 11, 2025 03:10
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a null dereference exception in Task logging that occurs when Task.Start and Task.Wait are called concurrently. The race condition can cause the task's m_action field to be nulled out during execution, leading to an ArgumentNullException when EventSource-based tracing attempts to extract the method name from a null delegate.

Key changes:

  • Added null check for m_action before using it in logging
  • Introduced pattern matching to safely capture the delegate reference
  • Removed defensive Debug.Assert that was no longer applicable

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-threading-tasks
See info in area-owners.md if you want to be subscribed.

@stephentoub stephentoub merged commit 745d230 into dotnet:main Sep 12, 2025
146 checks passed
@stephentoub stephentoub deleted the fixtplnull branch September 12, 2025 01:49
@stephentoub stephentoub added this to the 11.0.0 milestone Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NullReferenceException when Task is Start-ed and Wait-ed concurrently
2 participants