MsalClientException: The same command was already received and is being processed.
See original GitHub issueDescribe 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:
- Created 3 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top GitHub Comments
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.Fixed in 2.0.1. Please reopen or file a new issue if you have any problems. Thanks!