Skip to content

Commit 3119c78

Browse files
authored
Dispose of old cancellationTokenSource instances during revalidation cycle (#46736)
1 parent 303115a commit 3119c78

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Components/Server/src/Circuits/RevalidatingServerAuthenticationStateProvider.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ public RevalidatingServerAuthenticationStateProvider(ILoggerFactory loggerFactor
3131
// existing revalidation loop and start a new one
3232
AuthenticationStateChanged += authenticationStateTask =>
3333
{
34-
_loopCancellationTokenSource?.Cancel();
34+
var oldCancellationTokenSource = _loopCancellationTokenSource;
35+
if (oldCancellationTokenSource is not null)
36+
{
37+
oldCancellationTokenSource.Cancel();
38+
oldCancellationTokenSource.Dispose();
39+
}
40+
3541
_loopCancellationTokenSource = new CancellationTokenSource();
3642
_ = RevalidationLoop(authenticationStateTask, _loopCancellationTokenSource.Token);
3743
};

0 commit comments

Comments
 (0)