angular-auth-oidc-client
angular-auth-oidc-client copied to clipboard
[Bug]: "Injector has already been destroyed" error during silent renew causes isAuthenticated to return false
Version
15.0.4
Issue
We are having issues with developers getting kicked out of our app. It seems like this is caused by the refresh session process colliding with the frontend code being recompiled. The silent renew process starts, but the code recompiling causes the "Injector has already been destroyed" error, which subsequently causes the silent renew to fail with error.
Is there a convenient way to handle this edge case?
Please provide the exception or error you saw
[DEBUG] 0-spa - Has accessToken expired: true --> expires in -1:0-1 , 13:23:53 > 13:23:54
angular-auth-oidc-client.mjs:64 [DEBUG] 0-spa - starting silent renew...
angular-auth-oidc-client.mjs:64 [DEBUG] 0-spa - BEGIN refresh session Authorize
angular-auth-oidc-client.mjs:64 [DEBUG] 0-spa - RefreshSession created. Adding myautostate: bf32288c5cf1aa1debf82d06b8fca01b8dBAfrAm0
angular-auth-oidc-client.mjs:64 [DEBUG] 0-spa - found refresh code, obtaining new credentials with refresh code
angular-auth-oidc-client.mjs:58 [ERROR] 0-spa - OidcService code request https://localhost:8001 Error: NG0205: Injector has already been destroyed.
at R3Injector.assertNotDestroyed (core.mjs:7975:19)
at R3Injector.runInContext (core.mjs:7870:14)
at HttpInterceptorHandler.chain (http.mjs:1393:57)
at HttpInterceptorHandler.handle (http.mjs:1441:21)
at http.mjs:1220:70
at doInnerSub (mergeInternals.js:19:19)
at outerNext (mergeInternals.js:14:57)
at OperatorSubscriber._next (OperatorSubscriber.js:13:21)
at OperatorSubscriber.next (Subscriber.js:31:18)
at Observable._subscribe (innerFrom.js:51:24)
angular-auth-oidc-client.mjs:64 [DEBUG] 0-spa - Local Login information cleaned up and event fired
angular-auth-oidc-client.mjs:58 [ERROR] 0-spa - silent renew failed! Error: Error: OidcService code request https://localhost:8001
at angular-auth-oidc-client.mjs:3516:37
Steps to reproduce the behavior
No response
A clear and concise description of what you expected to happen.
No response
Additional context
No response
Is anyone able to help with this? I have attached a screenshot of the error.
Is anyone able to help with this?
I am a little lost what to do here. This error comes when you reload when developing, right?
Correct. The reload causes the silentRenew to fail, which then causes the library to sign the developer out of the app.
The lib can not know when there is a reload 🤔🤔🤔🤔🤔
Unfortunately this is also sometimes happening without a reload. The silent renew is failing and it's unclear why...
I have added more verbose logs to show where the problem is happening exactly:
This happens every time the silent renew process is happening, regardless of whether the frontend code is recompiled...
Is there anything we can do about this? Or do we just ignore this as part of development process?
Can you provide a minimal sample repo to reproduce the issue? Because we have never seen it.
Not really, without providing the entire application. Is it possible that this is coming from the AuthInterceptor?
Maybe. Have you tried updating to the latest version? Have you thrown it out the interceptor and tried to do your own?
I will try it now, thanks. If not maybe I can make a custom interceptor though!
Unfortunately the above does not fix the issue. Silent renew still fails with the same error messages.
I keep encountering this sometimes, but only during HMR replacements. @joewIST are you using HMR by any chance? I'm on 16.0.0
.
In development mode we use HMR. The issue is this is even happening during non-HMR replacements, i.e. if you don't do anything/don't recompile the code, it's still occurring. We have been trying to diagnose this problem for months and cannot seem to find a solution.