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.

MsalClientException: The same command was already received and is being processed.

See original GitHub issue

Describe the bug

In this app I have the authentication set up so that the current access token is added to the request headers, then when the request fails because of a 401 Unauthorized response we call ISingleAccountPublicClientApplication.acquireTokenSilentAsync to get a new token and then retry the request with this token. This is solved by using an OkHttp Interceptor that does that. Unfortunately more often than not, when the current access token expires (which seems to be a couple of hours) the refresh fails with the exception com.microsoft.identity.client.exception.MsalClientException: The same command was already received and is being processed.. This causes the user to be logged out of the app (this is how we handle unrecoverable 401 errors) so this is quite a serious issue in this app.

Smartphone (please complete the following information):

  • Device: OnePlus 6T (and more)
  • Android Version: Android 10
  • Browser Chrome
  • MSAL Version 1.5.1

Stacktrace

    com.microsoft.identity.client.exception.MsalClientException: The same command was already received and is being processed.
        at com.microsoft.identity.client.internal.controllers.MsalExceptionAdapter.msalExceptionFromBaseException(MsalExceptionAdapter.java:51)
        at com.microsoft.identity.client.SingleAccountPublicClientApplication$3.onError(SingleAccountPublicClientApplication.java:339)
        at com.microsoft.identity.client.SingleAccountPublicClientApplication$3.onError(SingleAccountPublicClientApplication.java:325)
        at com.microsoft.identity.common.internal.controllers.CommandDispatcher$1.run(CommandDispatcher.java:93)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
     Caused by: com.microsoft.identity.common.exception.ClientException: The same command was already received and is being processed.
        at com.microsoft.identity.common.internal.controllers.CommandDispatcher$1.run(CommandDispatcher.java:93) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

To Reproduce Probably calling acquireTokenSilentAsync a second time (on a different thread) before the first one completes.

Expected behavior The acquireTokenSilentAsync function should return a new token without any error.

Actual Behavior The acquireTokenSilentAsync function threw an exception in onError

Probably related to #847 but that one’s closed.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
z3ntucommented, Aug 26, 2020

As long as I’m getting a token back and not an error, I’m happy. 😄 Also FTR I also currently have a synchronized(...) { } block around the MSAL call to avoid this issue and it seems to work around that reliably.

1reaction
iambmeltcommented, Sep 23, 2020

Fixed in 2.0.1. Please reopen or file a new issue if you have any problems. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

MsalClientException Class | Microsoft Learn
The same command is already be processed. final String, DUPLICATE_QUERY_PARAMETER. Extra query parameters set by the client app is already sent by the...
Read more >
Unable to create SingleAccountPublicClientApplication for ...
What solved it for me was re-doing the app registration process on the azure portal, and when you create the hash on the...
Read more >
Azure AD Login - The browser based authentication dialog ...
Problem. I am receiving the error “The browser based authentication dialog failed to complete. Reason: the server or proxy was not found” ......
Read more >
MsalClientException (msal 2.2.3 API) - Javadoc.io
Duplicate command. The same command is already be processed. See Also: Constant Field Values. APP_MANIFEST_VALIDATION_ERROR. public static final java.lang.
Read more >
Access Token Not Found In Cache
Use Case For APIs secured with OAuth, Access Token is obtained from the token ... first one has to check if the access...
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