Skip to content

[release/10.0] Fix intermittent NRE in ETW listener tests by using GUID overload of EnableProvider - #138098

Merged
lewing merged 1 commit into
release/10.0from
backport/pr-125908-to-release/10.0
Nov 23, 2026
Merged

lewing merged 1 commit into
release/10.0from
backport/pr-125908-to-release/10.0

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #125908 to release/10.0

Spotted on release/10.0 in #138054 (build 1693559, net10.0-windows-Release-x64-coreclr_checked): Test_BadEventSource_MismatchedIds_WithEtwListener failed with the same NullReferenceException in TraceEventProviders.GetProviderGuidByName.

/cc @lewing @copilot

Customer Impact

  • Customer reported
  • Found internally

[Select one or both of the boxes. Describe how this issue impacts customers, citing the expected and actual behaviors and scope of the issue. If customer-reported, provide the issue number.]

Regression

  • Yes
  • No

[If yes, specify when the regression was introduced. Provide the PR or commit if known.]

Testing

[How was the fix verified? How was the issue missed previously? What tests were added?]

Risk

[High/Medium/Low. Justify the indication by mentioning how risks were measured and addressed.]

Note

The release/10.0 failure link was added with GitHub Copilot assistance.

…EnableProvider (#125908)

`BasicEventSourceTests` ETW tests intermittently fail with
`NullReferenceException` in `TraceEventProviders.GetProviderGuidByName`
under CI stress (PGO, jitstress). The string overload of
`EnableProvider` resolves the name via `TdhEnumerateProviders` (Win32),
which intermittently returns `ERROR_INSUFFICIENT_BUFFER`, yielding a
null provider dictionary.

## Description

**Root cause:** `EtwListener.ApplyEventSourceCommand` called
`_session.EnableProvider(string, ...)`, which internally calls
`TdhEnumerateProviders` — a Windows API that transiently fails under
load.

**Fix:** Switch the `Enable` path to use the GUID overload, consistent
with how `DisableProvider` already works in the same method:

```csharp
// Before
_session.EnableProvider(eventSourceName, (TraceEventLevel)options.Level, (ulong)options.Keywords, ...);

// After — GUID is computed deterministically; no TdhEnumerateProviders call
var providerGuid = TraceEventProviders.GetEventSourceGuidFromName(eventSourceName);
_session.EnableProvider(providerGuid, (TraceEventLevel)options.Level, (ulong)options.Keywords, ...);
```

`GetEventSourceGuidFromName` computes the EventSource GUID
algorithmically from the name (same as the runtime itself), so no
registry/ETW enumeration is needed.

> [!NOTE]
> This content was generated with AI assistance (GitHub Copilot).

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>


----

*This section details on the original issue you should resolve*

<issue_title>Test failure
BasicEventSourceTests.TestsUserErrors.Test_BadEventSource_MismatchedIds_WithEtwListener</issue_title>
<issue_description>## Build Information
Build:
https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=762567
Build error leg or test failing:
BasicEventSourceTests.TestsUserErrors.Test_BadEventSource_MismatchedIds_WithEtwListener
Pull request: #105777
<!-- Error message template  -->
## Error Message

Fill the error message using [step by step known issues
guidance](https://github.com/dotnet/arcade/blob/main/Documentation/Projects/Build%20Analysis/KnownIssueJsonStepByStep.md).

<!-- Use ErrorMessage for String.Contains matches. Use ErrorPattern for
regex matches (single line/no backtracking). Set BuildRetry to `true` to
retry builds with this error. Set ExcludeConsoleLog to `true` to skip
helix logs analysis. -->

```json
{
  "ErrorMessage": "BasicEventSourceTests.TestsUserErrors.Test_BadEventSource_MismatchedIds_WithEtwListener [FAIL]",
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}
```


**Failed in:** [runtime-coreclr libraries-pgo
20240114.1](https://dev.azure.com/dnceng-public/public/_build/results?buildId=526820&view=ms.vss-test-web.build-test-results-tab&runId=12404250&resultId=136092&paneView=debug)

**Failed tests:**
```
net9.0-windows-Release-x86-CoreCLR_checked-fullpgo_methodprofiling-Windows.10.Amd64.Open
    - BasicEventSourceTests.TestsUserErrors.Test_BadEventSource_MismatchedIds_WithEtwListener
```

**Error message:**
```
System.NullReferenceException : Object reference not set to an instance of an object.
```

**Stack trace:**
```
   at Microsoft.Diagnostics.Tracing.Session.TraceEventProviders.GetProviderGuidByName(String name)
   at Microsoft.Diagnostics.Tracing.Session.TraceEventSession.EnableProvider(String providerName, TraceEventLevel providerLevel, UInt64 matchAnyKeywords, TraceEventProviderOptions options)
   at BasicEventSourceTests.EtwListener.EventSourceCommand(String eventSourceName, EventCommand command, FilteringOptions options) in /_/src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/Harness/EtwListener.cs:line 77
   at BasicEventSourceTests.TestsUserErrors.Test_Bad_EventSource_Startup(Boolean onStartup, Listener listener, EventSourceSettings settings) in /_/src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestsUserErrors.cs:line 115
   at BasicEventSourceTests.TestsUserErrors.Test_BadEventSource_MismatchedIds_WithEtwListener() in /_/src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestsUserErrors.Etw.cs:line 48
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args) in /_/src/coreclr/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.CoreCLR.cs:line 36
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs:line 57
```

<!-- Known issue validation start -->
 ### Known issue validation
**Build: 🔎**
https://dev.azure.com/dnceng-public/public/_build/results?buildId=762567
**Error message validated:**
`[BasicEventSourceTests.TestsUserErrors.Test_BadEventSource_MismatchedIds_WithEtwListener
[FAIL]`]
**Result validation:** ✅ Known issue matched with the
provided build.
**Validation performed at:** 8/4/2024 3:24:07 AM UTC
<!-- Known issue validation end -->
<!--Known issue error report start -->

### Report

|Build|Definition|Test|Pull Request|
|---|---|---|---|

|[1346041](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1346041)|dotnet/runtime|[BasicEventSourceTests.TestsWrite.Test_Write_T_ETW](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1346041&view=ms.vss-test-web.build-test-results-tab&runId=37594902&resultId=131497)|dotnet/runtime#125010|

|[1342233](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1342233)|dotnet/runtime|[BasicEventSourceTests.TestsWriteEvent.Test_WriteEvent_SelfDescribing_ETW](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1342233&view=ms.vss-test-web.build-test-results-tab&runId=37485304&resultId=123634)|dotnet/runtime#124738|

|[1335226](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1335226)|dotnet/runtime|[BasicEventSourceTests.TestsWrite.Test_Write_T_ETW](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1335226&view=ms.vss-test-web.build-test-results-tab&runId=37296014&resultId=136917)||

|[1311626](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1311626)|dotnet/runtime|[BasicEventSourceTests.TestsW...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #96968

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: danmoseley <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@lewing lewing added the test-bug Problem in test source code (most likely) label Nov 23, 2026
@lewing
lewing enabled auto-merge (squash) November 23, 2026 01:10
@lewing lewing added Servicing-approved Approved for servicing release area-Infrastructure labels Nov 23, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@lewing lewing self-assigned this Nov 23, 2026
@lewing

lewing commented Nov 23, 2026

Copy link
Copy Markdown
Member

/ba-g failures have active prs for servicing

@lewing
lewing merged commit 8dd92e0 into release/10.0 Nov 23, 2026
116 of 120 checks passed
@lewing
lewing deleted the backport/pr-125908-to-release/10.0 branch November 23, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Infrastructure Servicing-approved Approved for servicing release test-bug Problem in test source code (most likely)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants