Skip to content

Fix EventPipe method events on CoreCLR WASM and harden the Blazor EventPipe test - #132474

Merged
pavelsavara merged 2 commits into
dotnet:mainfrom
pavelsavara:fix_ep_wbt
Aug 19, 2026
Merged

Fix EventPipe method events on CoreCLR WASM and harden the Blazor EventPipe test#132474
pavelsavara merged 2 commits into
dotnet:mainfrom
pavelsavara:fix_ep_wbt

Conversation

@pavelsavara

Copy link
Copy Markdown
Member

Summary

This change fixes a runtime crash surfaced by the Blazor EventPipe diagnostics tests on
CoreCLR/WASM and makes the test itself resilient so that a runtime trap is reported as a
test failure instead of hanging the whole Helix work item. It also fixes the emsdk path
fallback used by CoreCLR Wasm.Build.Tests local runs.

Changes

src/coreclr/vm/eventtrace.cpp — guard method ETW events against unregistered code

ETW::MethodLog::SendMethodEvent and ETW::MethodLog::SendMethodILToNativeMapEvent
construct an EECodeInfo from a code start address and then immediately query the JIT
manager for region and debug info. When the address does not map to a registered JIT
manager, EECodeInfo is not valid and the subsequent calls dereference invalid state,
crashing the runtime while an EventPipe session collects rundown/method events.

Both functions now bail out early when !codeInfo.IsValid(), since there is no region
info to report for such an address. This is the root-cause fix for the trap observed by
BlazorEventPipeTestWithCpuSamples on CoreCLR.

src/mono/wasm/Wasm.Build.Tests/Blazor/EventPipeDiagnosticsTests.cs — fail fast instead of hang

Previously ClickAndCollect awaited globalThis.donePromise unconditionally. When the
runtime traps, it catches the exception, logs a console error and exits non-zero, so the
promise is never settled and EvaluateAsync (which has no timeout of its own) waits until
the entire Helix work item is killed — hiding the real failure.

The test now:

  • Subscribes to page.PageError and page.Console and treats a non-zero WASM EXIT <code>
    message (or an unhandled page error) as a runtime failure, surfacing the last console
    error text.
  • Bounds the wait on donePromise with an explicit s_traceCollectionTimeout (3 minutes —
    generous for slow CI but well under the work-item budget), racing it against the
    runtime-failure signal via Task.WhenAny.
  • On timeout/failure, calls Assert.Fail with a descriptive message and defuses the
    now-orphaned EvaluateAsync task (which faults on page teardown) so it does not resurface
    as an unobserved task exception in a later test.
  • Restores the event handlers in a finally block.

BlazorEventPipeTestWithCpuSamples is annotated with
[ActiveIssue("https://github.com/dotnet/runtime/issues/132410", ..., IsCoreClrRuntime)]
so it is tracked while the CPU-samples path on CoreCLR is stabilized.

src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj — fix CoreCLR emsdk fallback

CoreCLR WBT local runs need EMSDK_PATH for BrowserWasmApp.CoreCLR.targets. The prior
fallback pointed at an in-repo emsdk directory under the browser project root that does
not exist for CoreCLR, yielding a path that never resolved.

The fallback now points at the shared wasm tool cache ($(EmscriptenSdkCacheDir)) and is
gated on its .complete stamp ($(EmscriptenSdkStampFile)), matching how
eng/AcquireEmscriptenSdk.targets and eng/testing/tests.browser.targets resolve the SDK.
When the cache is not provisioned the property is left empty, producing the actionable
"either set $(EMSDK_PATH), or use workloads" error instead of a bogus path.

Note

This PR description was generated with the assistance of GitHub Copilot.

Copilot AI lite review requested due to automatic review settings August 18, 2026 16:07
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Aug 18, 2026
@azure-pipelines

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

@pavelsavara pavelsavara added this to the 12.0.0 milestone Aug 18, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Comment thread src/mono/wasm/Wasm.Build.Tests/Blazor/EventPipeDiagnosticsTests.cs Outdated

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 a CoreCLR/WASM runtime crash during EventPipe method rundown by guarding method ETW event emission against unregistered code addresses, and hardens the Blazor EventPipe diagnostics test so runtime traps are surfaced as test failures (with a bounded wait) rather than hanging the Helix work item. Also corrects the local CoreCLR emsdk fallback path used by Wasm.Build.Tests.

Changes:

  • Add EECodeInfo::IsValid() guards in ETW::MethodLog to avoid dereferencing invalid JIT manager state during method event emission.
  • Update ClickAndCollect in Blazor EventPipe diagnostics tests to detect runtime failure via Playwright console/page error hooks and enforce a trace-collection timeout.
  • Fix CoreCLR EMSDK_PATH fallback to use the shared wasm tool cache when provisioned, leaving it empty otherwise for a clearer error.

Reviewed changes

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

File Description
src/coreclr/vm/eventtrace.cpp Adds validity checks before querying region/debug info from EECodeInfo, preventing crashes when the address isn’t mapped to a registered JIT manager.
src/mono/wasm/Wasm.Build.Tests/Blazor/EventPipeDiagnosticsTests.cs Makes trace collection bounded and failure-aware (console/page error detection + timeout) to avoid hangs on runtime traps.
src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj Adjusts CoreCLR emsdk fallback resolution to the shared tool cache gated by the SDK “complete” stamp.

Comment thread src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj
Copilot AI review requested due to automatic review settings August 18, 2026 16:17

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@pavelsavara
pavelsavara requested a review from maraf August 18, 2026 17:31
@pavelsavara

Copy link
Copy Markdown
Member Author

/ba-g unrelated failures

@pavelsavara
pavelsavara merged commit 22645b4 into dotnet:main Aug 19, 2026
108 of 111 checks passed
@pavelsavara
pavelsavara deleted the fix_ep_wbt branch August 19, 2026 06:14
@dotnet-milestone-bot dotnet-milestone-bot Bot modified the milestones: 12.0.0, 12.0-preview1 Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants