Skip to content

Remove unreliable assertions around Query and Fragment offsets#119557

Merged
MihaZupan merged 1 commit intomainfrom
MihaZupan-patch-1
Sep 11, 2025
Merged

Remove unreliable assertions around Query and Fragment offsets#119557
MihaZupan merged 1 commit intomainfrom
MihaZupan-patch-1

Conversation

@MihaZupan
Copy link
Member

Fixes #119547

#119547 (comment)

We have asserts that Query and Fragment offsets aren't populated if Flags.AllUriInfoSet isn't set (as we haven't finished parsing yet).

runtime/src/libraries/System.Private.Uri/src/System/Uri.cs

Lines 180 to 181 in 80dbb9f

Debug.Assert(offset.Query == 0);
Debug.Assert(offset.Fragment == 0);
The asserts have a race condition since a different thread may have done the parsing between us checking the flag and reading the offsets. Introduced in #117287.

Might have to backport that to 10.0 as well if it creates too much CI noise.

@MihaZupan MihaZupan added this to the 11.0.0 milestone Sep 10, 2025
@MihaZupan MihaZupan self-assigned this Sep 10, 2025
Copilot AI review requested due to automatic review settings September 10, 2025 22:26
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 fixes a race condition in URI parsing assertions by removing unreliable debug assertions for Query and Fragment offsets. The issue occurs when multiple threads access the same URI instance during parsing, causing assertions to fail when one thread checks parsing flags while another thread has already populated the offsets.

  • Removes two debug assertions that check Query and Fragment offsets are zero
  • Adds explanatory comment about the race condition with multi-threaded access
  • Maintains other assertions that remain valid in multi-threaded scenarios

@dotnet-policy-service
Copy link
Contributor

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

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

LGTM

@MihaZupan MihaZupan enabled auto-merge (squash) September 11, 2025 00:15
@MihaZupan MihaZupan merged commit 08aa6a2 into main Sep 11, 2025
90 checks passed
@MihaZupan MihaZupan deleted the MihaZupan-patch-1 branch September 11, 2025 10:49
@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 2025
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.

System.Uri.AssertInvariants failing with debug assert: offset.Query == 0

3 participants