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

Skip to content

[OpenApi] Fix thread static use and write directly to PipeWriter #61700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025

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