angular-auth-oidc-client icon indicating copy to clipboard operation
angular-auth-oidc-client copied to clipboard

[Bug]: "Injector has already been destroyed" error during silent renew causes isAuthenticated to return false

Open joewIST opened this issue 1 year ago • 15 comments

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

joewIST avatar May 09 '23 12:05 joewIST

Is anyone able to help with this? I have attached a screenshot of the error.

image

joewIST avatar Jun 02 '23 10:06 joewIST

Is anyone able to help with this?

joewIST avatar Jul 24 '23 15:07 joewIST

I am a little lost what to do here. This error comes when you reload when developing, right?

FabianGosebrink avatar Jul 24 '23 16:07 FabianGosebrink

Correct. The reload causes the silentRenew to fail, which then causes the library to sign the developer out of the app.

joewIST avatar Jul 24 '23 16:07 joewIST

The lib can not know when there is a reload 🤔🤔🤔🤔🤔

FabianGosebrink avatar Jul 24 '23 16:07 FabianGosebrink

Unfortunately this is also sometimes happening without a reload. The silent renew is failing and it's unclear why...

joewIST avatar Jul 25 '23 06:07 joewIST

I have added more verbose logs to show where the problem is happening exactly:

image

This happens every time the silent renew process is happening, regardless of whether the frontend code is recompiled...

joewIST avatar Jul 26 '23 15:07 joewIST

Is there anything we can do about this? Or do we just ignore this as part of development process?

joewIST avatar Aug 31 '23 07:08 joewIST

Can you provide a minimal sample repo to reproduce the issue? Because we have never seen it.

FabianGosebrink avatar Aug 31 '23 07:08 FabianGosebrink

Not really, without providing the entire application. Is it possible that this is coming from the AuthInterceptor?

joewIST avatar Aug 31 '23 07:08 joewIST

Maybe. Have you tried updating to the latest version? Have you thrown it out the interceptor and tried to do your own?

FabianGosebrink avatar Aug 31 '23 07:08 FabianGosebrink

I will try it now, thanks. If not maybe I can make a custom interceptor though!

joewIST avatar Aug 31 '23 07:08 joewIST

Unfortunately the above does not fix the issue. Silent renew still fails with the same error messages.

joewIST avatar Aug 31 '23 15:08 joewIST

I keep encountering this sometimes, but only during HMR replacements. @joewIST are you using HMR by any chance? I'm on 16.0.0.

ravindUwU avatar Sep 05 '23 04:09 ravindUwU

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.

joewIST avatar Sep 05 '23 06:09 joewIST