You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cancelling a FileSystem/Temp/ConfigHome/DataHome persistence call mid-operation throws PersistenceProviderException instead of OperationCanceledException #121
FileSystemPersistenceProvider and TempPersistenceProvider wrap every operation in catch (Exception ex) { throw new PersistenceProviderException(...) }. That catch also captures the OperationCanceledException / TaskCanceledException thrown by the token-aware calls awaited inside the try:
FileSystemPersistenceProvider.StoreAsync: SerializeAsync (line 62) and WriteAllTextAsync (line 73), wrapped at line 82.
FileSystemPersistenceProvider.RetrieveAsync: ReadAllTextAsync (line 105) and DeserializeAsync (line 112), wrapped at line 114.
TempPersistenceProvider has the same structure, with catches at lines 79 and 111.
ConfigHome and DataHome delegate to FileSystemPersistenceProvider, so they inherit the problem.
ThrowIfCancellationRequested() runs before the try, so only a token that is already cancelled on entry produces a real OCE. If cancellation arrives during the operation, the caller gets a PersistenceProviderException whose InnerException is the TaskCanceledException.
The sibling InMemoryPersistenceProvider throws a plain OCE in the same situation. Standard .NET cancellation handling (catch (OperationCanceledException), Task.IsCanceled, ASP.NET request-abort handling, Parallel/Channel consumers) therefore sees a cancelled save as a storage failure. The result is error logs, retries, or a "save failed" message shown to the user.
Reproduction
The setup is FileSystemPersistenceProvider<string> over InMemoryFileSystemProvider, with a test ISerializationProvider whose TrySerialize writes the value and then calls cts.Cancel() to simulate the token firing mid-operation.
await p.StoreAsync("k", "value", cts.Token);
→ ktsu.Essentials.PersistenceProviderException inner=System.Threading.Tasks.TaskCanceledException:
Failed to store object with key 'k' to file system
Expected: OperationCanceledException.
Suggested fix
Let cancellation pass through every catch-all in both providers. Either:
add catch (OperationCanceledException) { throw; } before the wrapping catch, or
use catch (Exception ex) when (ex is not OperationCanceledException).
Open PR #116 (for #66) rewrites the body of StoreAsync but keeps the catch-all. This fix should either rebase onto that PR or be folded into it.
Acceptance criteria
For FileSystem, Temp, ConfigHome and DataHome, a token cancelled during StoreAsync or RetrieveAsync produces an OperationCanceledException, not a PersistenceProviderException.
A contract test covers this using a serializer or file-system test double that cancels mid-operation.
Failures that are not cancellations are still wrapped in PersistenceProviderException.
Activity
matt-edmondson commentedon Oct 17, 2026
Triage
FileSystemPersistenceProvider,TempPersistenceProvider;ConfigHome/DataHomeinherit the problem).catch (Exception ex) when (ex is not OperationCanceledException)in both providers, and add a contract test that cancels mid-operation.Generated by Claude Code