loculus-project / loculus

An open-source software package to power microbial genomic databases
https://loculus.org
GNU Affero General Public License v3.0
37 stars 2 forks source link

`isLoggedIn` errors, probably before Keycloak is initialised #1163

Closed theosanderson closed 8 months ago

theosanderson commented 8 months ago

Astro logs can read:

06:25:48 PM [@astrojs/node] Server listening on http://localhost:3000{"instance":"LoginMiddleware","level":"debug","message":"Trying to get token and user info from cookie","timestamp":"2024-02-27T18:25:57.919Z"}{"instance":"LoginMiddleware","level":"debug","message":"Trying to get token and user info from params","timestamp":"2024-02-27T18:25:57.921Z"}
{"instance":"LoginMiddleware","level":"info","message":"Getting keycloak client for issuer url: http://loculus-keycloak-service:8083/realms/loculusRealm","timestamp":"2024-02-27T18:25:57.922Z"}06:25:57 PM [ssr] Error: connect ECONNREFUSED 10.43.52.122:8083    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16){"instance":"LoginMiddleware","level":"debug","message":"Trying to get token and user info from cookie","timestamp":"2024-02-27T18:25:57.971Z"}{"instance":"LoginMiddleware","level":"debug","message":"Trying to get token and user info from params","timestamp":"2024-02-27T18:25:57.972Z"}
{"instance":"LoginMiddleware","level":"info","message":"Getting keycloak client for issuer url: http://loculus-keycloak-service:8083/realms/loculusRealm","timestamp":"2024-02-27T18:25:57.972Z"}TypeError: Cannot read properties of undefined (reading 'isLoggedIn')    at file:///app/dist/server/chunks/pages/404_8037c3af.mjs:1950:44    at AstroComponentInstance.Navigation [as factory] (file:///app/dist/server/chunks/astro_7796fbdb.mjs:312:12)    at AstroComponentInstance.init (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1121:29)    at AstroComponentInstance.render (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1126:18)    at Object.render (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1644:22)    at renderChild 
(file:///app/dist/server/chunks/astro_7796fbdb.mjs:1077:17)    at process.processTicksAndRejections 

(node:internal/process/task_queues:95:5)file:///app/dist/server/chunks/pages/404_8037c3af.mjs:1950  const isLoggedIn = Astro2.locals.session.isLoggedIn;                                          
 ^TypeError: Cannot read properties of undefined (reading 'isLoggedIn')    at file:///app/dist/server/chunks/pages/404_8037c3af.mjs:1950:44    at AstroComponentInstance.Navigation [as factory] (file:///app/dist/server/chunks/astro_7796fbdb.mjs:312:12)    at AstroComponentInstance.init (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1121:29)    at AstroComponentInstance.render (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1126:18)    at Object.render (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1644:22)    at renderChild (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1077:17)    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)Node.js v20.11.1

This indicates we're not appropriately checking for the possibility of unset Astro session if keycloak can't be talked to

corneliusroemer commented 8 months ago

@fengelniederhammer also hit this today:

TypeError: Cannot read properties of undefined (reading 'isLoggedIn')
    at file:///app/dist/server/chunks/pages/404_d4dab6a9.mjs:1965:44
    at AstroComponentInstance.Navigation [as factory] (file:///app/dist/server/chunks/astro_7796fbdb.mjs:312:12)
    at AstroComponentInstance.init (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1121:29)
    at AstroComponentInstance.render (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1126:18)
    at Object.render (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1644:22)
    at renderChild (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1077:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
{"instance":"LoginMiddleware","level":"debug","message":"Trying to get token and user info from cookie","timestamp":"2024-03-04T10:53:11.676Z"}
{"instance":"LoginMiddleware","level":"debug","message":"Trying to get token and user info from params","timestamp":"2024-03-04T10:53:11.677Z"}
{"instance":"LoginMiddleware","level":"info","message":"Getting keycloak client for issuer url: http://loculus-keycloak-service:8083/realms/loculusRealm","timestamp":"2024-03-04T10:53:11.677Z"}
10:53:11 AM [ssr] Error: connect ECONNREFUSED 10.43.147.135:8083
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) (x2)
{"instance":"LoginMiddleware","level":"debug","message":"Trying to get token and user info from cookie","timestamp":"2024-03-04T10:53:11.684Z"}
{"instance":"LoginMiddleware","level":"debug","message":"Trying to get token and user info from params","timestamp":"2024-03-04T10:53:11.685Z"}
{"instance":"LoginMiddleware","level":"info","message":"Getting keycloak client for issuer url: http://loculus-keycloak-service:8083/realms/loculusRealm","timestamp":"2024-03-04T10:53:11.685Z"}
TypeError: Cannot read properties of undefined (reading 'isLoggedIn')
    at file:///app/dist/server/chunks/pages/404_d4dab6a9.mjs:1965:44
    at AstroComponentInstance.Navigation [as factory] (file:///app/dist/server/chunks/astro_7796fbdb.mjs:312:12)
    at AstroComponentInstance.init (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1121:29)
    at AstroComponentInstance.render (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1126:18)
    at Object.render (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1644:22)
    at renderChild (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1077:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
file:///app/dist/server/chunks/pages/404_d4dab6a9.mjs:1965
  const isLoggedIn = Astro2.locals.session.isLoggedIn;
                                           ^

TypeError: Cannot read properties of undefined (reading 'isLoggedIn')
    at file:///app/dist/server/chunks/pages/404_d4dab6a9.mjs:1965:44
    at AstroComponentInstance.Navigation [as factory] (file:///app/dist/server/chunks/astro_7796fbdb.mjs:312:12)
    at AstroComponentInstance.init (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1121:29)
    at AstroComponentInstance.render (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1126:18)
    at Object.render (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1644:22)
    at renderChild (file:///app/dist/server/chunks/astro_7796fbdb.mjs:1077:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Looks like session is not always there, when keycloak fails. So we should properly catch errors and log instead of crash.