Skip to content

Fix DiagnosticListener IsEnabled cyclical dispatch and lost activity hooks - #130582

Merged
steveisok merged 1 commit into
dotnet:mainfrom
steveisok:steveisok-solid-potato
Jul 14, 2026
Merged

Fix DiagnosticListener IsEnabled cyclical dispatch and lost activity hooks#130582
steveisok merged 1 commit into
dotnet:mainfrom
steveisok:steveisok-solid-potato

Conversation

@steveisok

Copy link
Copy Markdown
Member

Fixes two bugs in DiagnosticListener reported in #125306:

  1. The Subscribe overloads taking a Func<string, object?, object?, bool> isEnabled predicate passed 'name => IsEnabled(name, null, null)' as the 1-arg IsEnabled callback. This routed a plain IsEnabled(string) call back through the public IsEnabled(string, object?, object?) method, causing unnecessary indirection and incorrectly invoking subclass overrides of the 3-arg IsEnabled during a 1-arg call. The callback now closes over the caller's delegate directly.

  2. DiagnosticSubscription.Remove rebuilt linked-list nodes without copying the OnActivityImport and OnActivityExport fields, silently dropping those activity hooks when an earlier-subscribed node was removed. Remove now copies both fields.

Adds regression tests covering both scenarios.

Fixes #125306

…hooks

Fixes two bugs in DiagnosticListener reported in dotnet#125306:

1. The Subscribe overloads taking a Func<string, object?, object?, bool>
   isEnabled predicate passed 'name => IsEnabled(name, null, null)' as the
   1-arg IsEnabled callback. This routed a plain IsEnabled(string) call back
   through the public IsEnabled(string, object?, object?) method, causing
   unnecessary indirection and incorrectly invoking subclass overrides of the
   3-arg IsEnabled during a 1-arg call. The callback now closes over the
   caller's delegate directly.

2. DiagnosticSubscription.Remove rebuilt linked-list nodes without copying the
   OnActivityImport and OnActivityExport fields, silently dropping those
   activity hooks when an earlier-subscribed node was removed. Remove now
   copies both fields.

Adds regression tests covering both scenarios.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @dotnet/area-system-diagnostics-tracing
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes two correctness issues in System.Diagnostics.DiagnosticSource’s DiagnosticListener subscription plumbing: (1) avoids routing the 1-arg IsEnabled(string) fast-path through the virtual 3-arg IsEnabled(string, object?, object?) override when a 3-arg predicate was supplied, and (2) preserves activity import/export hooks when rebuilding the immutable subscription linked list during removal. Adds targeted regression tests.

Changes:

  • Update Subscribe(..., Func<string, object?, object?, bool> ...) overloads to close over the caller-provided predicate directly for the 1-arg IsEnabled callback, avoiding unintended virtual dispatch/indirection.
  • Fix DiagnosticSubscription.Remove to copy OnActivityImport / OnActivityExport when rebuilding nodes.
  • Add regression tests covering both the IsEnabled routing bug and the activity-hook loss on subscription removal.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/libraries/System.Diagnostics.DiagnosticSource/tests/DiagnosticSourceTests.cs Adds regression tests for IsEnabled(string) routing and activity hook preservation across subscription removal.
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceActivity.cs Fixes the activity-hook Subscribe overload’s 1-arg IsEnabled callback to invoke the provided predicate directly.
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticListener.cs Fixes the core Subscribe overload’s 1-arg IsEnabled callback and preserves activity hooks during subscription list rebuild in Remove.

@noahfalk noahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fyi @tarekgh

@steveisok
steveisok merged commit e48caed into dotnet:main Jul 14, 2026
89 of 91 checks passed
@steveisok
steveisok deleted the steveisok-solid-potato branch July 14, 2026 00:45
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 14, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
…hooks (#130582)

Fixes two bugs in DiagnosticListener reported in #125306:

1. The Subscribe overloads taking a Func<string, object?, object?, bool>
isEnabled predicate passed 'name => IsEnabled(name, null, null)' as the
1-arg IsEnabled callback. This routed a plain IsEnabled(string) call
back through the public IsEnabled(string, object?, object?) method,
causing unnecessary indirection and incorrectly invoking subclass
overrides of the 3-arg IsEnabled during a 1-arg call. The callback now
closes over the caller's delegate directly.

2. DiagnosticSubscription.Remove rebuilt linked-list nodes without
copying the OnActivityImport and OnActivityExport fields, silently
dropping those activity hooks when an earlier-subscribed node was
removed. Remove now copies both fields.

Adds regression tests covering both scenarios.

Fixes #125306

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

DiagnosticListener: Cyclical IsEnabled reference and Activity action disappearance

3 participants