Skip to content

Fix OOM from unbounded enumeration of ExtendedLogger tag joiners - #7819

Merged
evgenyfedorov2 merged 1 commit into
mainfrom
evgenyfedorov2-fix-tag-joiner-self-enumeration-oom
Oct 9, 2026
Merged

evgenyfedorov2 merged 1 commit into
mainfrom
evgenyfedorov2-fix-tag-joiner-self-enumeration-oom

Conversation

@evgenyfedorov2

@evgenyfedorov2 evgenyfedorov2 commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Fixes: #7505

Microsoft Reviewers: Open in CodeFlow

@evgenyfedorov2
evgenyfedorov2 force-pushed the evgenyfedorov2-fix-tag-joiner-self-enumeration-oom branch from 2e55a3b to 97ec24b Compare October 8, 2026 12:04
LegacyTagJoiner and ModernTagJoiner enumerated their tags with a loop bounded
by Count, which includes the joiner's extra tags. When a joiner was enumerated
while tags were being added to that same list, the enumeration never ended and
memory grew until an OutOfMemoryException. This happens, for example, when a
logging provider forwards a lazily wrapped log state to another extended logger
on the same thread, because all extended loggers on a thread share one joiner.

The enumerators now capture the number of extra tags when enumeration starts
and iterate each group of tags separately, in the same order as the indexer, so
that "{OriginalFormat}" remains the last tag.

Fixes #7505

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@evgenyfedorov2
evgenyfedorov2 force-pushed the evgenyfedorov2-fix-tag-joiner-self-enumeration-oom branch from 97ec24b to d57bfbb Compare October 8, 2026 12:06
@evgenyfedorov2
evgenyfedorov2 marked this pull request as ready for review October 8, 2026 12:07
@evgenyfedorov2
evgenyfedorov2 requested a review from a team as a code owner October 8, 2026 12:07
Copilot AI balanced review requested due to automatic review settings October 8, 2026 12:07

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.

🟢 Approval recommended

Both implementations address the reported failure and include focused regression tests; tests were not executed.

0 open findings

What changed in this PR

Fixes #7505 by preventing unbounded self-enumeration in ExtendedLogger tag joiners, avoiding out-of-memory failures.

Changes:

  • Bounds enumeration of enrichment tags while preserving tag order.
  • Adds regression tests for both joiners, capped to prevent runaway memory use.
File Description
test/​Libraries/​Microsoft.Extensions.Telemetry.Tests/​Logging/​TagJoinerTests.cs Adds bounded self-enumeration regression tests.
src/​Libraries/​Microsoft.Extensions.Telemetry/​Logging/​ExtendedLogger.ModernTagJoiner.cs Enumerates tag groups with a fixed enrichment-tag count.
src/​Libraries/​Microsoft.Extensions.Telemetry/​Logging/​ExtendedLogger.LegacyTagJoiner.cs Separates incoming-tag count and bounds enrichment-tag enumeration.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@dotnet-comment-bot

Copy link
Copy Markdown
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.Diagnostics.Testing Line 99 98.65 🔻
Microsoft.Extensions.Telemetry Line 93 92.32 🔻
Microsoft.Extensions.AI.OpenAI Line 75 68.32 🔻
Microsoft.Extensions.AI.OpenAI Branch 75 57.59 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Line 75 4.46 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Branch 75 0 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Line 99 96.03 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Branch 99 92.76 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Line 99 97.73 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Line 75 42.11 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Branch 75 42.86 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Line 75 69.93 🔻
Microsoft.Extensions.ServiceDiscovery Line 75 67.96 🔻
Microsoft.Extensions.ServiceDiscovery Branch 75 71.43 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Line 75 73.85 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Branch 75 70 🔻
Microsoft.Extensions.VectorData.Abstractions Line 75 37.39 🔻
Microsoft.Extensions.VectorData.Abstractions Branch 75 22.73 🔻

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.Http.Diagnostics 94 95
Microsoft.Gen.BuildMetadata 97 100
Microsoft.Gen.MetadataExtractor 57 73
Microsoft.Gen.MetricsReports 67 69
Microsoft.Extensions.AI.Abstractions 82 86
Microsoft.Extensions.AI.Evaluation.NLP 0 78
Microsoft.Extensions.Caching.Hybrid 82 85
Microsoft.Extensions.DataIngestion 75 89
Microsoft.Extensions.DataIngestion.Markdig 75 90
Microsoft.Extensions.Http.Resilience 97 100

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1628008&view=codecoverage-tab

@evgenyfedorov2
evgenyfedorov2 merged commit 453a10c into main Oct 9, 2026
6 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Telemetry Logging] LegacyTagJoiner and ModernTagJoiner could cause OutOfMemoryException

4 participants