Skip to content

[GreenDonut] Fix single-key LoadAsync caching a promise for a cancelled token - #149

Merged
michaelstaib merged 2 commits into
mst/stream-v2from
mst/greendonut-load-cancelled-token
Nov 2, 2026
Merged

michaelstaib merged 2 commits into
mst/stream-v2from
mst/greendonut-load-cancelled-token

Conversation

@michaelstaib

Copy link
Copy Markdown
Owner

The single-key DataLoaderBase.LoadAsync(key, ct) now checks the token before it touches the cache, like the many-key overload already does. Before, a call with an already-cancelled token still added a promise to the cache, and the batch cancelled it afterwards.

LoadAsync_Should_ThrowAndLeaveCacheEmpty_When_TokenIsCancelled checks that the call throws OperationCanceledException and that the cache stays empty. It fails without the fix.

GreenDonut.Tests passes on net10 and net8, and GreenDonut.Data.Tests passes on net10. The Docker-backed EF tests were not run. No benchmark was run. The change adds one token check per call.

Copilot AI balanced review requested due to automatic review settings November 1, 2026 07:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the single-key cancellation-handling change.

No open issues 🎉

What changed in this PR

Fixes GreenDonut’s single-key LoadAsync path so an already-cancelled token throws before accessing the cache, matching the many-key overload.

Changes:

  • Adds an early cancellation check to prevent caching a promise for an already-cancelled request.
  • Adds a regression test verifying that cancellation throws OperationCanceledException and leaves the cache empty.
File Description
src/​GreenDonut/​test/​GreenDonut.Tests/​DataLoaderTests.cs Tests cancellation handling and an unchanged empty cache.
src/​GreenDonut/​src/​GreenDonut/​DataLoaderBase.cs Checks cancellation before single-key cache access.

Review effort: Balanced

@michaelstaib
michaelstaib merged commit e894034 into mst/stream-v2 Nov 2, 2026
1 check passed
@michaelstaib
michaelstaib deleted the mst/greendonut-load-cancelled-token branch November 2, 2026 07:34
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