Skip to content

[release/10.0] Don't cache truncated/aborted responses in OutputCacheMiddleware - #68770

Open
DeagleGross wants to merge 1 commit into
dotnet:release/10.0from
DeagleGross:deaglegross-backport-output-cache-rel-10
Open

[release/10.0] Don't cache truncated/aborted responses in OutputCacheMiddleware#68770
DeagleGross wants to merge 1 commit into
dotnet:release/10.0from
DeagleGross:deaglegross-backport-output-cache-rel-10

Conversation

@DeagleGross

Copy link
Copy Markdown
Member

Backport of #68683 to release/10.0. Source merge commit: bbc2649.

Prevents truncated or aborted responses from being stored or shared with requests waiting on the same output-cache key. Waiters now re-execute when the in-flight response was not actually cached.

Validation: 108 OutputCacheMiddlewareTests passed on net10.0.

…otnet#68683)

OutputCacheMiddleware could store a response whose body was cut short,
and share that entry with requests waiting on the same cache key.

FinalizeCacheBodyAsync now skips storage when the request was aborted and
reports whether the response was cached. The caller releases the pending
entry unless it was actually stored, so waiters re-execute instead of
receiving a truncated body.

Fixes dotnet#66877
Copilot AI lite review requested due to automatic review settings August 25, 2026 10:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Backports a fix to OutputCacheMiddleware (release/10.0) to prevent truncated or aborted responses from being cached or shared with concurrent waiters for the same output-cache key, ensuring waiters re-execute when the in-flight response wasn’t actually cached.

Changes:

  • Updates the locking/pending-entry flow to only reuse an in-flight response when FinalizeCacheBodyAsync reports it was cached.
  • Extends FinalizeCacheBodyAsync to return a boolean and to skip caching when RequestAborted is already canceled.
  • Adds/extends tests to cover aborted and truncated responses, including locking scenarios.
Show a summary per file
File Description
src/Middleware/OutputCaching/src/OutputCacheMiddleware.cs Tracks whether a response was cached and releases pending entries when it wasn’t, plus skips caching on aborted requests.
src/Middleware/OutputCaching/test/OutputCacheMiddlewareTests.cs Adds regression tests for aborted/truncated responses and verifies locking waiters re-execute instead of receiving incomplete responses.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

await OutputCacheEntryFormatter.StoreAsync(context.CacheKey, context.CachedResponse, context.Tags, context.CachedResponseValidFor,
_store, _logger, context.HttpContext.RequestAborted);

return true;
@wtgodbe wtgodbe added the Servicing-approved Shiproom has approved the issue label Aug 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hi @DeagleGross. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed.

@rbhanda rbhanda added this to the 10.0.13 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants