UI: store.getters.zones.filter is not a function on first login for User-type roles (race between listZones and listApis)

Offen Anfängerfreundlich
#14,847 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
javascript
Bereich
frontend

Rechercherichtung

Beginne mit ui/src/store/modules/user.js und verfolge GetInfo zusammen mit listZones, listApis und GenerateRoutes, um die gemeldete Race Condition zu bestätigen. Untersuche anschließend die show-Funktionen in ui/src/config/section/network.js und die vnfapp-Details auf die anderen nicht abgesicherten Zonenabfragen. Das Issue ist abgeschlossen, wenn eine neue Anmeldung mit der beschriebenen Rolle ohne den Konsolenfehler geladen wird; überprüfe das gemeldete Verhalten in einer neuen privaten Sitzung.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug
problem

On a fresh session the UI stays empty and the console shows:

TypeError: store.getters.zones.filter is not a function
    at Object.show (network.js)
    ...
    at GenerateRoutes (permission.js)

A reload (F5) fixes it. We see it for users with a User-type role and a short API list; a DomainAdmin user with a longer API list usually does not hit it.

Cause: in ui/src/store/modules/user.js the state starts with zones: {} (an object, not an array). GetInfo starts listZones and listApis in parallel and dispatches GenerateRoutes as soon as listApis returns, without waiting for listZones. When listApis returns first, the show of the securitygroups section in ui/src/config/section/network.js calls store.getters.zones.filter(...) on {}. The createNetwork show and the vnfapp details have the same unguarded call. On a reload the cached branch of GetInfo commits the zones from local storage before anything else, so there is no race.

versions

Apache CloudStack 4.22.1.0 (management server and UI), KVM, advanced zones. Login via SAML2 (Keycloak). The same code (zones: {} and no wait on listZones before GenerateRoutes) is on the 4.22 branch and on main.

The steps to reproduce the bug
  1. Create a custom role of type User with a short allow-list that includes listApis, listZones, listSecurityGroups, listUsers, listCapabilities, listLdapConfigurations, listNetworkServiceProviders and cloudianIsEnabled, ending with *,deny.
  2. Create an account with that role and a user, and authorise the user for SAML.
  3. Open a new private browser window and log in through SAML.
  4. In the network tab, listApis returns before listZones; the UI stays empty and the console shows store.getters.zones.filter is not a function.
  5. Press F5: the UI loads normally.

It is timing dependent: the shorter the API list of the role, the more often listApis wins.

What to do about it?
  • Initialise zones as [] in the state of ui/src/store/modules/user.js.
  • Wait for listZones (and SET_ZONES) before dispatching GenerateRoutes in GetInfo.
  • Guard the show functions in ui/src/config/section/network.js (and the vnfapp details) with Array.isArray(store.getters.zones).

Any one of the first two fixes the race; the guard makes the menu robust against a missing zone list.

Vorherrschende Sprache
Java
Sterne
3.1k
Forks
1.4k
Ø Merge
6 T. 1 Std.
Gemergte PRs (30 T.)
16

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus apache/cloudstack

Alle Issues in apache/cloudstack

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.