Skip to content

Fix regex test OOM on x86 checked coreclr#126007

Open
danmoseley wants to merge 2 commits intodotnet:mainfrom
danmoseley:fix/regex-oom-x86-checked
Open

Fix regex test OOM on x86 checked coreclr#126007
danmoseley wants to merge 2 commits intodotnet:mainfrom
danmoseley:fix/regex-oom-x86-checked

Conversation

@danmoseley
Copy link
Member

Four System.Text.RegularExpressions.Tests tests fail with OutOfMemoryException on the x86 checked coreclr leg. The SourceGenerated regex engine path runs full Roslyn compilations at test time, and large batches (up to ~2,903 patterns) exhaust the ~2GB x86 address space — especially with 4 parallel xunit threads and checked runtime overhead.

Changes

  1. Chunk batches on 32-bit (RegexGeneratorHelper.netcoreapp.cs): When !Environment.Is64BitProcess, compile at most 200 patterns per Roslyn invocation instead of all at once. No change on 64-bit.

  2. Skip CharClassSubtraction_DeepNesting_DoesNotStackOverflow on 32-bit (Regex.Match.Tests.cs): The 1000-depth nested char class BDD exhausts address space via a different mechanism (recursive RegexNodeConverter.CreateBDDFromSetString). This test was added 3 weeks ago in Fix StackOverflowException from deeply nested character class subtractions #124995 and already had to be skipped on browser-wasm (Skip NonBacktracking deep nesting test on single-threaded WASM #125021).

Failing tests covered

Test Patterns OOM location
RegexPcre2Tests.IsMatchTests ~2,903 DefiniteAssignmentPass (Array.Resize)
MonoTests.ValidateRegex ~1,008 BlobBuilder (Roslyn emit)
RegexGroupTests.Groups ~631 Source generator compilation
CharClassSubtraction_DeepNesting N/A RegexNodeConverter.CreateBDD

Fixes #126003

Chunk SourceGenRegexAsync batches to 200 patterns on 32-bit processes
to avoid OutOfMemoryException from Roslyn compiling thousands of
patterns at once in the ~2GB address space.

Skip CharClassSubtraction_DeepNesting_DoesNotStackOverflow on 32-bit
as the 1000-depth nested BDD exhausts address space.

Fixes dotnet#126003

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danmoseley
Copy link
Member Author

I think the recently added CharClassSubtraction_DeepNesting is what pushed this over the edge, the chunking is reasonable extra change here

@dotnet-policy-service
Copy link
Contributor

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

@danmoseley danmoseley enabled auto-merge (squash) March 24, 2026 02:35
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

This PR addresses OutOfMemoryException failures in System.Text.RegularExpressions.Tests on the x86 checked CoreCLR test leg by reducing peak memory usage in source-generated regex compilation and skipping a deep-nesting stress test on 32-bit processes.

Changes:

  • Chunk source-generator Roslyn compilations into smaller batches on 32-bit processes to avoid exhausting the ~2GB address space.
  • Skip CharClassSubtraction_DeepNesting_DoesNotStackOverflow on 32-bit processes to avoid address-space exhaustion in deep BDD construction paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexGeneratorHelper.netcoreapp.cs Adds 32-bit-only batching (max 200 patterns per compilation) for source-generated regex creation.
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Match.Tests.cs Adds a 32-bit guard to skip the deep nesting char class subtraction test.

… list

- Use [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))]
  instead of runtime check, matching the pattern used by StressTestDeepNestingOfLoops
- Pre-allocate List<Regex> with regexes.Length capacity to avoid resizing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

System.Text.RegularExpressions.Tests: multiple tests OOM on x86 checked coreclr

2 participants