Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] CacheSynchronizationEnabled flag default is inconsistent #4268

Closed
bgavrilMS opened this issue Jul 24, 2023 · 4 comments · Fixed by #4310
Closed

[Bug] CacheSynchronizationEnabled flag default is inconsistent #4268

bgavrilMS opened this issue Jul 24, 2023 · 4 comments · Fixed by #4310
Assignees
Labels
bug confidential-client ICM This issue has a corresponding ICM, either for our team or another. P2 scenario:DaemonApp
Milestone

Comments

@bgavrilMS
Copy link
Member

bgavrilMS commented Jul 24, 2023

MSAL 4.54.1

Expected

CacheSynchronizationEnabled should be true by default. It should have negligible impact over when CCA is constructed on a request by request basis. But when CCA is singleton, cache correctness cannot be achieved without this flag set to true (i.e. without locking).

(It should also be hidden / soft deprecated API, as it is too low level)

Actual

If using ApplicationOptions when constructing the CCA object, the CacheSynchronizationEnabled is set to false if not explicitly declared.
If not using ApplicationsOptions, the CacheSynchronizationEnabled is set to true

@bgavrilMS
Copy link
Member Author

bgavrilMS commented Jul 24, 2023

CC @jennyf19 and @jmprieur as this affects Id.Web since afaik it constructs the CCA from options all the time.

To minimize churn, is it possible to set this flag to false when you create a CCA per request and to true when in singleton mode? That way MSAL can change its default as it sees fit.

@jmprieur
Copy link
Contributor

Yes, we might be able to do that in Id.Web.
However what about the customers not using Id.Web? isn't that a problem

@bgavrilMS bgavrilMS added this to the 4.56.0 milestone Jul 25, 2023
@bgavrilMS bgavrilMS added the ICM This issue has a corresponding ICM, either for our team or another. label Aug 16, 2023
@pmaytak pmaytak self-assigned this Aug 23, 2023
@pmaytak pmaytak modified the milestones: 4.56.0, 4.55.1 Aug 23, 2023
@pmaytak
Copy link
Contributor

pmaytak commented Aug 24, 2023

But when CCA is singleton, cache correctness cannot be achieved without this flag set to true (i.e. without locking).

Nit clarification here - CCA is singleton and token cache serialization is enabled.

So the effects of changing default from false to true:

# Scenario Effect
1 CCA is per request w/ serialized cache Negligible
2 Singleton CCA, no serialized cache Not recommended, should not be used in prod.
3 Singleton CCA w/ serialized cache Fixes cache inconsistency

We don't have telemetry how often 2 is used in prod.

I also wouldn't obsolete this in case people want to set the flag to false in scenario 2 or 1. I would just make sure the method comment is clear that defaults should be used.

@pmaytak
Copy link
Contributor

pmaytak commented Aug 24, 2023

So the flag is consistent - it's false by default.

var options = new ConfidentialClientApplicationOptions()
{
ClientSecret = "secret",
ClientId = TestConstants.ClientId,
};
var app = ConfidentialClientApplicationBuilder.CreateWithApplicationOptions(options).Build();
Assert.IsFalse((app.AppConfig as ApplicationConfiguration).CacheSynchronizationEnabled);

app = ConfidentialClientApplicationBuilder.Create(Guid.NewGuid().ToString()).WithClientSecret(TestConstants.ClientSecret).BuildConcrete();
Assert.IsFalse((app.AppConfig as ApplicationConfiguration).CacheSynchronizationEnabled);

Although it is set to true in app config; it's actually overridden in the CcaBuilder.Create:

public bool CacheSynchronizationEnabled { get; internal set; } = true;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug confidential-client ICM This issue has a corresponding ICM, either for our team or another. P2 scenario:DaemonApp
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants