Skip to content

Add retry for StackTraceTests.ToString_ShowILOffset AMSI hang#125814

Merged
danmoseley merged 3 commits intodotnet:mainfrom
danmoseley:fix-stacktrace-amsi-flake
Mar 20, 2026
Merged

Add retry for StackTraceTests.ToString_ShowILOffset AMSI hang#125814
danmoseley merged 3 commits intodotnet:mainfrom
danmoseley:fix-stacktrace-amsi-flake

Conversation

@danmoseley
Copy link
Member

The ToString_ShowILOffset test's Assembly.Load(byte[]) case triggers an AMSI (Antimalware Scan Interface) scan via Windows Defender RPC. On some Helix CI machines, this RPC call hangs indefinitely on NtAlpcConnectPort, causing the 60-second RemoteExecutor timeout.

This is an external Windows OS/Defender issue, not a .NET bug (diagnosed in #122690 by @jkotas).

Changes

  • Split the Assembly.Load(byte[]) case into its own test method (ToString_ShowILOffset_ByteArrayLoad) so an AMSI hang no longer drags down the other two stable cases (LoadFrom and AssemblyBuilder).
  • Added retry logic with up to 3 attempts and a 30s timeout. Each retry spawns a fresh child process via RemoteExecutor, giving the AMSI RPC a new chance to succeed.

Fixes #125599

The ToString_ShowILOffset test's Assembly.Load(byte[]) case triggers an
AMSI (Antimalware Scan Interface) scan via Windows Defender RPC. On some
CI machines, this RPC call hangs indefinitely on NtAlpcConnectPort,
causing a 60-second RemoteExecutor timeout (see dotnet#125599, dotnet#122690).

Split the byte[] case into its own test method (ToString_ShowILOffset_ByteArrayLoad)
with a shorter 30s timeout and up to 3 retry attempts. This isolates the
flaky AMSI-dependent case from the other two stable cases (LoadFrom and
AssemblyBuilder), and retries with a fresh child process when the OS-level
hang occurs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 20, 2026 00:33
@danmoseley danmoseley requested a review from adamsitnik March 20, 2026 00:34
@dotnet-policy-service
Copy link
Contributor

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Reduces CI flakiness caused by occasional Windows Defender AMSI hangs during Assembly.Load(byte[]) in stack trace tests by isolating the scenario and retrying it under a shorter RemoteExecutor timeout.

Changes:

  • Split the Assembly.Load(byte[]) scenario into its own test method.
  • Add retry (up to 3 attempts) with a 30s RemoteExecutor timeout for the AMSI-prone scenario.
  • Keep existing stable cases (LoadFrom / AssemblyBuilder) in the original test.

- Restrict retry to Windows only (AMSI is Windows-specific) per @jkotas
- Only retry on timeout, not assertion failures (check message)
- Use Assert.Throws for explicit throw assertion

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danmoseley danmoseley requested a review from Copilot March 20, 2026 01:00
Copy link
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 2 comments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danmoseley danmoseley requested a review from Copilot March 20, 2026 01:09
Copy link
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 2 comments.

@danmoseley danmoseley enabled auto-merge (squash) March 20, 2026 01:15
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.

Test failure: System.Diagnostics.Tests.StackTraceTests.ToString_ShowILOffset

3 participants