Skip to content

fix: prevent race condition when span count approaches the 1000-span limit#5227

Merged
jamescrosswell merged 2 commits into
maui-trace-ui-5116from
fix/issue-5173-spanlimit-race
May 13, 2026
Merged

fix: prevent race condition when span count approaches the 1000-span limit#5227
jamescrosswell merged 2 commits into
maui-trace-ui-5116from
fix/issue-5173-spanlimit-race

Conversation

@jamescrosswell
Copy link
Copy Markdown
Collaborator

Summary

  • Wraps AddChildSpan in a Lock so concurrent span creation cannot race past the 1000-span ceiling or incorrectly set IsSampled under contention
  • Adds StartChild_Limit_Maintained_Concurrently test using Parallel.For to reproduce the race

Fixes #5173

Targets #5138 (maui-trace-ui-5116) — intended to be merged there rather than directly to main.

🤖 Generated with Claude Code

…limit

Wraps AddChildSpan in a lock so concurrent span creation cannot exceed
the limit or set IsSampled incorrectly under contention.

Fixes #5173

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jamescrosswell jamescrosswell linked an issue May 13, 2026 that may be closed by this pull request
Resolved conflict in AddChildSpan: moved span limit check inside _finishLock
so the race condition fix and the finish/idle-timeout guard share a single lock,
removing the need for a separate _childSpanLock. Kept SpanLimit constant and
debug logging from the target branch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (maui-trace-ui-5116@a5e40d9). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/Sentry/TransactionTracer.cs 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##             maui-trace-ui-5116    #5227   +/-   ##
=====================================================
  Coverage                      ?   74.05%           
=====================================================
  Files                         ?      502           
  Lines                         ?    18261           
  Branches                      ?     3571           
=====================================================
  Hits                          ?    13523           
  Misses                        ?     3863           
  Partials                      ?      875           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamescrosswell jamescrosswell marked this pull request as ready for review May 13, 2026 04:25
@jamescrosswell jamescrosswell requested a review from Flash0ver as a code owner May 13, 2026 04:25
@jamescrosswell jamescrosswell merged commit 4a1d0ec into maui-trace-ui-5116 May 13, 2026
36 checks passed
@jamescrosswell jamescrosswell deleted the fix/issue-5173-spanlimit-race branch May 13, 2026 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TOCTOU race in TransactionTracer.AddChildSpan span-limit check

1 participant