Skip to content

[QUIC] Do not allocate exception if it might not be used#127526

Merged
MihaZupan merged 1 commit intodotnet:mainfrom
ManickaP:quic-exception-alloc
Apr 29, 2026
Merged

[QUIC] Do not allocate exception if it might not be used#127526
MihaZupan merged 1 commit intodotnet:mainfrom
ManickaP:quic-exception-alloc

Conversation

@ManickaP
Copy link
Copy Markdown
Member

Fixes #127455
Validation manual on the repro code, before:
before
after (no more QuicException):
after

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

@ManickaP ManickaP requested a review from a team April 28, 2026 19:03
@MihaZupan MihaZupan added this to the 11.0.0 milestone Apr 28, 2026
Copy link
Copy Markdown
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

Reduces avoidable allocations on the QUIC stream shutdown path by preventing creation of an OperationAborted QuicException when it cannot be observed (because the stream start task source is already completed). This aligns with the perf investigation in #127455 and targets the high-frequency shutdown event path for HTTP/3 server scenarios.

Changes:

  • Guard _startedTcs.TrySetException(ThrowHelper.GetOperationAbortedException()) behind _startedTcs.IsCompleted to avoid allocating an exception that would be ignored.
  • Preserve existing shutdown completion semantics while reducing handled exception churn.

Copy link
Copy Markdown
Member

@rzikm rzikm left a comment

Choose a reason for hiding this comment

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

LGTM. I assume you looked at other places where we might allocate exceptions unnecessarily?

@ManickaP
Copy link
Copy Markdown
Member Author

ManickaP commented Apr 29, 2026

Yep, the only other place interesting was connection shutdown. But we still need it to complete the accept queueu there, so I'm pretty sure this PR is the only relevant place.

@ManickaP
Copy link
Copy Markdown
Member Author

/ba-g #127500

@MihaZupan MihaZupan merged commit 03df392 into dotnet:main Apr 29, 2026
91 of 94 checks passed
@ManickaP ManickaP deleted the quic-exception-alloc branch April 29, 2026 08:23
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.

Too many (handled?) QuicException instances on HTTP/3 server side

6 participants