Repository navigation
Thread request cancellation through get_store_host (#4203) - #4412
Merged
Merged
Conversation
Links the request cancellation token into StoreHostProfileCache's gather delegate (CreateLinkedTokenSource plus the existing fixed deadline), removes get_store_host from CancellationAllowlist, and passes RequestAborted at its dispatch entry. A cancelled gather is never cached, and StoreHostProfileCache.GetOrGatherAsync now checks cancellation ahead of its semaphore gate so cancellation surfaces as OperationCanceledException rather than the semaphore's own TaskCanceledException subtype.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refs #4203.
Why
get_store_hostwas still onCancellationAllowlist: its read goes throughStoreHostProfileCache.GetOrGatherAsync, whose gather delegate ran inside its own fixed-deadlineCancellationTokenSourcewith no link to the caller's request token, so an abandoned or superseded web/MCP request left the gather running to that deadline instead of stopping when the caller went away.What changes
get_store_host(DarlingMcpStoreHostTools.cs). It now takes a trailingCancellationToken cancellationToken = default, links it with the cache's fixed deadline viaCancellationTokenSource.CreateLinkedTokenSource(cancellationToken)+CancelAfter(...)(either side can now stop the gather), and narrows its catch towhen (ex is not OperationCanceledException).StoreHostProfileCache.GetOrGatherAsyncnow checkscancellationToken.ThrowIfCancellationRequested()ahead of its semaphore gate, so a cancellation before the gate throwsOperationCanceledExceptiondirectly rather than the semaphore's ownTaskCanceledExceptionsubtype (the ratchet test asserts the exact base type).DarlingWebEndpoints.cs: removedget_store_hostfromCancellationAllowlist; its dispatch entry now passescancellationToken: c.RequestAborted.StoreHostProfileCacheTests.AFailedGather_IsNotCachedalready proved for any other exception; addedACancelledGather_IsNotCachedalongside it.WebReadCancellationPinTests: the existing ratchet (AConvertedReadEndpoint_ObservesCancellation_InsteadOfDialingTheStore,EveryStoreReadingToolMethod_TakesACancellationToken_UnlessAllowlisted,CancellationAllowlist_HasNoStaleEntry) now enforces this tool for free — no new test needed there. Its dispatch-table theory previously calledBuildReadDispatch()with noPostgresConfig, which madeget_store_hostshort-circuit to an "unavailable" envelope before touching the store; that call now passes a dead-storePostgresConfigso the theory actually reaches the gather path for this tool, same as every other entry.Test plan
In-process
Darling.Tests.dllrun on macOS (xunit v3 in-process runner):WebReadCancellationPinTests: 123/123 passed.StoreHostProfileCacheTests: 5/5 passed (includes the newACancelledGather_IsNotCached).origin/devatbd8a2661c) with the new test files copied in via a detached worktree,AConvertedReadEndpoint_ObservesCancellation_InsteadOfDialingTheStore(name: "get_store_host")failed ("No exception was thrown") andEveryStoreReadingToolMethod_TakesACancellationToken_UnlessAllowlistedfailed, namingget_store_hostas an offender — both green after the fix.Darling.Tests.csprojandLite.Tests.csprojboth 0 errors withEnableWindowsTargeting=true.Darling.Tests.dllsuite run once: 15105 total, 226 failed, 966 skipped. All 226 failures are the pre-existing macOS/WPF-platform set (Viewer*, install-location ACL tests, deploy-script tests, etc. — types touchingPresentationFrameworkor Windows-only filesystem/ACL APIs) unrelated to this change; none touchStoreHostProfileCache,DarlingMcpStoreHostTools, orDarlingWebEndpoints's dispatch/allowlist.Darling.Tests/Lite.Tests(net10.0-windows targets): build 0/0 here; cannot run on macOS, CI decides them — listed unchecked.CHANGELOG entry
SECTION: Fixed
ENTRY:
get_store_hostnow honours request cancellation ([Thread request cancellation through get_store_host (#4203) #4412]) - an abandoned or superseded call toget_store_hostkept its store-host gather running to the tool's own fixed deadline instead of stopping when the caller went away; the gather now also observes the request's own cancellation, and a cancelled gather is never cached.REF:
[Thread request cancellation through get_store_host (#4203) #4412]: Thread request cancellation through get_store_host (#4203) #4412