question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] The cache serialization callbacks should accept CancellationToken

See original GitHub issue

Even though the cache serialization callbacks return a Task, they do not accept a CancellationToken. Example is the SetBeforeAccessAsync

Accepting a CancellationToken as a parameter is important as partners onboard to distributed caches and invoke the MSAL APIs with a CancellationToken at the ExecuteAsync API.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bgavrilMScommented, Oct 15, 2021

I think Id.Web does consume it. The code is somewhat unclear, because we exposed an abstract class there and we chose to extend it using the “CacheSerializationHints” object, which contains the token. For example see https://github.com/AzureAD/microsoft-identity-web/blob/34325b3ae90fa84763a78ee454a3080bb07ae92f/src/Microsoft.Identity.Web.TokenCache/Distributed/MsalDistributedTokenCacheAdapter.cs#L261

Lessons learned:

  • “config” objects are a good way to extend functionality without breaking interfaces (or abstract classes, but I am not a fan of those)
  • never have an async method without a cancelation token.
1reaction
bgavrilMScommented, Oct 15, 2021

@rymeskar - If you look at the TokenCacheNotificationArgs, you’ll see a cancellation token there. This is the cancellation token that was given via AcquireToken***.ExecuteAsync(cancellationToken).

I agree that it would have been better to have SetBeforeAccessAsync with a cancellationToken from the start. But we didn’t, so we had to add it later.

The reason why we didn’t add an overload for SetBeforeAccessAsync this is because the callback are part of an interface ITokenCache, and we can’t ADD a method to an interface. Note that since we still have to support .net classic, we can’t use default interface methods. Thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature Request] In-memory shared cache cache in MSAL ...
implemeting cache serialization using the callbacks is easy to get wrong and isn't even the fully documented anymore (Microsoft.Identity.Web ...
Read more >
A Deep Dive into C#'s CancellationToken | by Mitesh Shah
Now whenever the source requests a cancellation, the registered callback will be called and cancellation occurs.
Read more >
Register callbacks for cancellation requests
If cancellation has already been requested when the callback is registered, the callback is still guaranteed to be called. In this particular ...
Read more >
CancellationToken vs CancellationChangeToken
The cancellation propagates to all cache entries that track the corresponding change token, and thus invalidates them all at once. Share.
Read more >
Scripting API: ISerializationCallbackReceiver
Interface to receive callbacks upon serialization and deserialization. Unity's serializer is able to serialize most datatypes, but not all of them.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found