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] AcquireTokenSilentSupplier failed: Token not found in the cache #833

Closed
joshfree opened this issue Jun 27, 2024 · 3 comments
Closed
Labels
confidential-client For issues related to confidential client apps public-client For questions/issues related to public client apps

Comments

@joshfree
Copy link

Ported issue filed by @krysiuda at Azure/azure-sdk-for-java#40654 to https://github.com/AzureAD/microsoft-authentication-library-for-java

Describe the bug
Between msal4j versions 1.14.0 and 1.15.0 logging for AuthenticationErrorCode.CACHE_MISS has changed. I believe the change was accidental, resulting in additional (and potentially misleading) WARN messages being log.

Exception or Stack Trace
Our production system is logging "Execution of class com.microsoft.aad.msal4j.AcquireTokenSilentSupplier failed: Token not found in the cache" on "com.microsoft.aad.msal4j.ConfidentialClientApplication" logger (severity: WARN) every hour.

Expected behavior
Since cache miss simply triggers retrieval of a new token, I would expect this event (cache miss) to be logged with low severity. Preferably DEBUG level.

Setup (please complete the following information):

  • OS: linux
  • IDE: IntelliJ
  • Library/Libraries: msal4j-1.15.0-sources.jar
  • Java version: openjdk-21
  • App Server/Environment: N/A
  • Frameworks: N/A

Additional context
in msal4j-1.14.0 AuthenticationResultSupplier there was:

            if (exception.errorCode() != null && exception.errorCode().equalsIgnoreCase(AuthenticationErrorCode.CACHE_MISS)) {
                clientApplication.log.debug(logMessage, ex);
                return;
            }
            ...
            clientApplication.log.error(logMessage, ex);

logging CACHE_MISS on DEBUG level instead of ERROR.

in msal4j-1.15.0, there is only:

                clientApplication.log.warn(
                        LogHelper.createMessage(
                                String.format("Execution of %s failed: %s", this.getClass(), ex.getMessage()),
                                msalRequest.headers().getHeaderCorrelationIdValue()));

logging cache misses always on WARN level.

@Avery-Dunn
Copy link
Collaborator

Hello @joshfree : I believe the most recent change to that logging level was in #756 as part of v1.14.1, b105389 is the relevant commit, and those changes were to resolve #662

If I remember right, the idea was to log at the 'warn' or 'debug' level rather than the 'error' level whenever an exception was thrown. However, as that code snippet you have points out there was a check specifically for putting cache misses at the debug level, and that was lost during the various logging changes done in v1.14.1

I agree that a cache miss exception should cause a debug log, since it doesn't necessarily mean that something wrong. It'll be a quick fix so will likely be in our next release, and I'll update this thread once we have some ETAs

@Avery-Dunn Avery-Dunn added public-client For questions/issues related to public client apps confidential-client For issues related to confidential client apps labels Jun 27, 2024
papaya2k pushed a commit to papaya2k/microsoft-authentication-library-for-java that referenced this issue Jul 23, 2024
Addresses GitHub Issue AzureAD#833 by reducing the logging level of a
CACHE_MISS in the AuthenticationResultSupplier to debug level.
@papaya2k
Copy link
Contributor

Hello. I've also been affected by this. The logging is definitely overly verbose. I've suggested a code correction for this to change the logging level of a CACHE_MISS to debug level. Thank you.

papaya2k added a commit to papaya2k/microsoft-authentication-library-for-java that referenced this issue Jul 23, 2024
Addresses GitHub Issue AzureAD#833 by reducing the logging level of a
CACHE_MISS in the AuthenticationResultSupplier to debug level.
papaya2k added a commit to papaya2k/microsoft-authentication-library-for-java that referenced this issue Jul 23, 2024
Addresses GitHub Issue AzureAD#833 by reducing the logging level of a
CACHE_MISS in the AuthenticationResultSupplier to debug level.
Avery-Dunn added a commit that referenced this issue Jul 25, 2024
Reduce logging level of CACHE_MISS <GitHub Issue #833>
@Avery-Dunn
Copy link
Collaborator

Thanks to @papaya2k, the logging level was reduced in #844, and was released in MSAL Java 1.16.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confidential-client For issues related to confidential client apps public-client For questions/issues related to public client apps
Projects
None yet
Development

No branches or pull requests

3 participants