Skip to content

Conversation

@kiryl-labada
Copy link

Fix form files when request buffering is enabled

When request buffering is enabled, processing files in parallel throws an exception

Description

When request body buffering is enabled, form files share a single underlying buffering stream. This causes a problem because a Stream cannot be read in parallel. When buffering is disabled, this issue does not occur, because each file is buffered separately.

The most straightforward solution is to buffer files regardless of how the request body is handled. However, to avoid negatively affecting performance for requests that contain only one file, the following optimization is applied:

  • The first FormFile references the request body stream directly (no memory or disk allocation).
  • All subsequent files are buffered.

Fixes #64843

@github-actions github-actions bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Dec 26, 2025
@kiryl-labada
Copy link
Author

@dotnet-policy-service agree

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Randomly unable to read IFormFile if use EnableBuffering

1 participant