Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

BrennanConroy
Copy link
Member

MemoryBufferWriter.Get() and Utf8BufferTextWriter.Get() are not supposed to be used in async code due to using [ThreadStatic] internally.

Additionally, we can write directly to the Response.BodyWriter instead of using a temporary via MemoryBufferWriter and avoid calling ToArray().

Copy link
Contributor

@Copilot 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 refactors the OpenAPI endpoint to eliminate the use of thread-static writers in async code and to write directly to Response.BodyWriter, avoiding unnecessary buffering and copying.

  • Removes the use of MemoryBufferWriter and the pool-based Utf8BufferTextWriter
  • Instantiates a new Utf8BufferTextWriter and sets it to write directly to Response.BodyWriter before serializing the document

@BrennanConroy BrennanConroy merged commit b212eb9 into main Apr 28, 2025
27 checks passed
@BrennanConroy BrennanConroy deleted the brecon/threadstatic branch April 28, 2025 21:22
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview5 milestone Apr 28, 2025
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.

2 participants