Skip to content

Static field initialization order bug in LoggingEventSource causes ParseFilterSpec to silently produce wrong rules #127681

Closed

Description

@hoyosjs

LoggingEventSource.ParseFilterSpec silently produces incorrect filter rules when OnEventCommand is invoked during the type's static initialization. s_semicolon and s_colon static fields are declared after the Instance field, so they are still null when the constructor runs and OnEventCommand fires re-entrantly due to a deferred event during the EventSource initialization. See:

Error callstack
 LoggingEventSource.<cctor>()                                              // Something ends up calling LoggingEventSource.Instance (probably on a log statement) which triggers static .
   LoggingEventSource.Instance = new LoggingEventSource() 
     EventSource(EventSourceSettings.EtwSelfDescribingEventFormat)          // base ctor
       Initialize(guid, name, traits)
         eventPipeProvider.Register(guid, name)
           EventPipeInternal.CreateProvider(name, &Callback, ctx)
             [native: EventPipe already has this provider enabled in active session]
             [native: calls Callback synchronously]
             // This callback sets  the HandleEnableNotification as a deferred command.
         [back in Initialize()]
         EventListener.AddEventSource(this)
         lock (EventListenersLock) {
           deferredCommands = m_deferredCommands
           DoCommand(deferredCommands)
               OnEventCommand(args)
                LoggingEventSource.OnEventCommand(args)                       // OVERRIDE
                  SetFilterSpec(value)                                        
                    ParseFilterSpec(filterSpec, defaultLevel)
                      filterSpec.Split(s_semicolon, ...)                      // s_semicolon is null.  splits on whitespace instead of ';'
         }
         m_completelyInited = true
     [constructor finishes]
   s_semicolon = new char[] { ';' }                                        // TOO LATE
   s_colon = new char[] { ':' }
 // .cctor finishes

This silently drops events and registers the wrong FilterSpec. This regressed in the 8.0 package timeframe.

Related

Activity

  1. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on May 2, 2026
  2. dotnet-policy-service commented on May 2, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  3. added and removed
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on May 2, 2026
  4. dotnet-policy-service commented on May 2, 2026

    @dotnet-policy-service
    Contributor

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

  5. added this to the 11.0.0 milestone on May 2, 2026
  6. locked and limited conversation to collaborators on Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions