[release/7.0.2xx] Revert hot reload script injection response buffering #29152
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.
Summary
Fixes a regression in memory consumption caused by large responses when debugging with hot reload enabled.
Description
As one of the changes introduced in .NET 7 by #27537, the hot reload script injection middleware now buffers the entire response before performing script injection. This was done to improve script injection reliability, but we recently began receiving reports from customers that were confused by the increase in server memory usage for large responses when debugging with hot reload is enabled.
This PR reverts the buffering behavior but keeps the logging improvements that help customers identify the cause of script injection failures and take steps to fix them.
For .NET 8, we will assess an alternative approach to improve script injection reliability that doesn't involve buffering each response.
Validation
Manual validation + existing automated tests for this scenario.
Risk
Low. This PR simply reverts the offending commit and adds back some of the improved logging behavior with no other changes to functionality.
Fixes dotnet/aspnetcore#45037