Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Entity service waitForEntity returns too early #2327

Open
richard-cox opened this issue Jun 12, 2018 · 1 comment
Open

Entity service waitForEntity returns too early #2327

richard-cox opened this issue Jun 12, 2018 · 1 comment

Comments

@richard-cox
Copy link
Contributor

  • To reproduce
    • Edit src/frontend/app/shared/components/add-service-instance/create-service-instance-helper.service.ts
    • comment out filter(o => !!o && !!o.entity && !!o.entity.entity && !!o.entity.entity.service_plans),
    • add filter(o => !!o && !!o.entity)
    • start afresh on the service instance wall
    • click 'edit' action on a service
    • exception thrown in console due to missing inline entity
  • What's going on under the hood
    • cf service is fetched without service_plans in service wall
    • in edit stepper entity service created for cf service entity, this states service_plans is required
    • waitForEntity is subbed to
    • cf service entity is validated, service_plans identified
    • validation process marks cf service is updating
    • service_plans are fetched and saved in store (and in line)
    • validation process marks cf service as not updating
    • However... before the service_plans response is stored in the store a stale service request info state is pumped up the observable chain, this doesn't have the updating flag and thus passes the waitForEntity filter
  • see branch rc-wait-for-bug
@richard-cox
Copy link
Contributor Author

Bumped into this again during #3326 (after fix that issue the code requires tweaking to reproduce this issue)
Basically as ValidateEntities process is done via actions/effects now instead of synchronous functions as before we let an entity through which does not have the required fields

  1. Entity service is created and getEntityObservable is called
  2. Finds an entity in store (with a missing relation)
  3. Kicks off asyncronously validation process (which will discover missing property, mark entity as updating, fetch missing property, mark entity as not updating)
  4. Async actions of validation do not occur quick enough for waitForEntity, which see's an entity that's not updating and returns an invalid entity
this.entityObs$ = this.getEntityObservable(
      entityMonitor,
      this.actionDispatch,
    ).pipe(
      publishReplay(1),
      refCount(),
      tap((entityInfo: EntityInfo) => {
        if (!entityInfo || entityInfo.entity) {
          if ((!validateRelations || validated || isEntityBlocked(entityInfo.entityRequestInfo))) {
            return;
          }
          validated = true;
          store.dispatch(new ValidateEntitiesStart(
            action as ICFAction,
            [entityInfo.entity.metadata.guid],
            false
          ));
        }
      })
    );

    this.waitForEntity$ = this.entityObs$.pipe(
      filter((ent) => {
        const { entityRequestInfo, entity } = ent;
        return this.isEntityAvailable(entity, entityRequestInfo);
      }),
      publishReplay(1),
      refCount()
    );

richard-cox added a commit that referenced this issue Jan 16, 2019
- We previously nuked the org's space collection when creating or deleting an org
- Validation was correctly then going to refetch this list, however waitForEntity is broken (see #2327) and emits an invalid action
- Later code takes invalid action an tries to access space
- Fix, aside from #2327, is yodate org space collection after space creation instead of nuking and waiting for validation to refetch
Other fixes
- Found sub leak in edit org stepper
- endpoint service allApps is subbed to in many places, ensure we share
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants