Repository navigation
Conversation
…ionsForCompletedTask (dotnet#136268) Signed-off-by: Omid Zaferi <omidzaferi@gmail.com>
|
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. |
This was referenced Oct 31, 2026
Open
jkotas
reviewed
Oct 31, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The change loses diagnostic stack traces on inner TaskCanceledException instances from WaitAll, requiring trace preservation and a regression assertion for their StackTrace.
1 open issue
What changed in this PR
This PR targets the Windows x86 stress-test OOM reported in #136268 by reducing canceled-task exception allocations in CoreLib’s Task.WaitAll path.
Changes:
- Adds canceled-task exceptions directly, avoiding per-task stack-trace capture and intermediate
AggregateExceptionallocations. - Retains existing exception retrieval for recorded faults and preserves exception-observation bookkeeping.
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs | Adds a cancellation-specific path in AddExceptionsForCompletedTask to reduce allocations. |
Review effort: Balanced
…ithout per-task capture OOM (dotnet#136268) Address review feedback by jkotas and Copilot: capture synthetic stack trace once per WaitAll invocation and share it across TaskCanceledException instances, eliminating OOM while preserving diagnostic stack traces and back-compat.
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-threading-tasks |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Fixes #136268.
In Windows x86 CoreCLR CI runs, System.Threading.Tasks.Tests.TaskContinueWithTests.RunContinueWithStressTestsNoState was failing with System.OutOfMemoryException inside StringBuilder.ToString().
Root Cause
When waiting on a large number of tasks (e.g., 5,000–10,000+ canceled continuation tasks in stress tests), Task.WaitAllCore iterates over all tasks and calls Task.AddExceptionsForCompletedTask(ref exceptions, task).
Previously, this routed through ask.GetExceptions(true), which for each canceled task:
ew StackTrace(fNeedFileInfo: true) and serializing the trace via StringBuilder allocations.
Under 32-bit x86 address space constraints (2GB user space), generating thousands of stack trace captures and strings concurrently caused address space exhaustion and OutOfMemoryException.
Fix
In Task.AddExceptionsForCompletedTask:
ew TaskCanceledException(t) to the exception list without triggering expensive stack trace formatting or intermediate AggregateException allocations.