Repository navigation
Do not return the DNS TCP buffer to the pool twice when growing it fails - #136585
Merged
EgorBo merged 2 commits intoOct 28, 2026
Merged
Conversation
When the length prefix of a DNS TCP response is larger than the rented buffer, SendTcpQueryAsync/SendTcpQuerySync returned the buffer to ArrayPool and then rented a larger one into the same variable. If that Rent threw (for example OutOfMemoryException), the variable still referred to the array that had just been returned, and the catch block returned it again. The pool could then hand the same array to two independent renters. Rent the larger buffer first, then return the old one and switch to the new one, so the variable always refers to an array that is still owned and is returned exactly once. Co-authored-by: Copilot <[email protected]> Copilot-Session: a13c23e0-b8e7-47bd-9714-cdc27528b527
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
The 2-byte length prefix bounds TCP responses to ushort.MaxValue, so renting that size up front removes the grow-and-swap path entirely. Co-authored-by: Copilot <[email protected]> Copilot-Session: f86ef291-922b-46a2-bed8-98845b7c4e0e
EgorBo
marked this pull request as draft
October 28, 2026 16:28
MihaZupan
approved these changes
Oct 28, 2026
This was referenced Oct 28, 2026
EgorBo
marked this pull request as ready for review
October 28, 2026 19:13
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.
When the length prefix of a DNS TCP response is larger than the rented buffer, SendTcpQueryAsync/SendTcpQuerySync returned the buffer to ArrayPool and then rented a larger one into the same variable. If that Rent threw (for example OutOfMemoryException), the variable still referred to the array that had just been returned, and the catch block returned it again. The pool could then hand the same array to two independent renters.
Rent the larger buffer first, then return the old one and switch to the new one, so the variable always refers to an array that is still owned and is returned exactly once.