Skip to content

EnableEvents for one EventListener seems to impact another EventListener #116883

Open
@orange-puff

Description

@orange-puff

Description

It seems that calling
EnableEvents for one instance of an EventListener is causing another instance to have events enabled for it. Not only that, it seems that disabling an EventSource for a specific instance of an EventListener will only stop some events from being written, but not EventCounters type events.

Reproduction Steps

This shows the behavior where enabling events for one EventListener enables EventCounters from the EventSource and the other EventListener receives those events.
https://github.com/orange-puff/EventListenerBugRepro/tree/main

This branch shows the behavior where disabling events for an instance of EventListener that enabled events for this EventSource only stops some events from being written to it, but not EventCounters. All EventListener which enabled events for a given EventSource need to disable it for EventCounters events to stop being written to them.
https://github.com/orange-puff/EventListenerBugRepro/tree/disabling-behavior

Expected behavior

https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.tracing.eventlistener?view=net-8.0
According to the docs;

Multiple event listeners can be defined in a single application domain. Each listener is logically independent of the other listeners so that events that are enabled or disabled by one listener affect only that listener. It is possible for commands sent with the SendCommand method to do a semantic operation (such as a garbage collection or flushing data) that affects the other listeners, but this is the exception rather than the rule.

This does not seem to be true

Actual behavior

After some experimentation and code reading, I think this is how it works:

  1. When an EventListener calls EnableEvents for an EventSource with EventCounterIntervalSec set in the args parameter, EventCounters from this EventSource will be sent to ALL EventListener . When EventCounterIntervalSec is not set, EventCounters events will not be sent.
    https://github.com/dotnet/dotnet/blob/main/src/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs#L56
  2. only after all EventListener which enabled events for the EventSource disable events for the EventSource will EventCounters for that EventSource stop being sent
    https://github.com/dotnet/dotnet/blob/main/src/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs#L81
  3. The first EventListener to call EnableEvents for an EventSource with EventCounterIntervalSec set in the args parameter will have its value used for the interval. Subsequent calls with different EventCounterIntervalSec will not be
    https://github.com/dotnet/dotnet/blob/main/src/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs#L163

used### Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions