Skip to content

Commit de61ffd

Browse files
committed
Clarify that the background task can't be cancelled
1 parent 37f28f8 commit de61ffd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/DataProtection/DataProtection/src/KeyManagement/KeyRingProvider.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ private IKeyRing GetCurrentKeyRingCoreNew(DateTime utcNow, bool forceRefresh)
365365
existingTask = Task.Factory.StartNew(
366366
utcNow => CacheableKeyRingProvider.GetCacheableKeyRing((DateTime)utcNow!),
367367
utcNow,
368-
CancellationToken.None,
368+
CancellationToken.None, // GetKeyRingFromCompletedTask will need to react if this becomes cancellable
369369
TaskCreationOptions.DenyChildAttach,
370370
TaskScheduler.Default);
371371
Volatile.Write(ref _cacheableKeyRingTask, existingTask);
@@ -433,7 +433,9 @@ private IKeyRing GetCurrentKeyRingCoreNew(DateTime utcNow, bool forceRefresh)
433433
return newCacheableKeyRing.KeyRing;
434434
}
435435

436-
var exception = task.Exception!;
436+
Debug.Assert(!task.IsCanceled, "How did a task with no cancellation token get canceled?");
437+
Debug.Assert(task.Exception is not null, "Task should have either completed successfully or with an exception");
438+
var exception = task.Exception;
437439

438440
var existingCacheableKeyRing = Volatile.Read(ref _cacheableKeyRing);
439441
if (existingCacheableKeyRing is not null && !CacheableKeyRing.IsValid(existingCacheableKeyRing, utcNow))

0 commit comments

Comments
 (0)