dxos-deprecated / echo

Eventually Consistent Hierarchical Objects Database
GNU Affero General Public License v3.0
0 stars 1 forks source link

Issues with opening party when reactivating #338

Closed rzadp closed 3 years ago

rzadp commented 3 years ago

There are issues with reactivating party.

The party is not (completely) open after activating.

This code:

console.log('activating..');
await party.activate({ global: true });
console.log('party.isActive()', party.isActive());
console.log('party.isOpen', party.isOpen);
console.log(`party.getProperty('displayName')`, party.getProperty('displayName'));

Effects in:

activating..
party.isActive() true
party.isOpen true

<Error>
AssertionError: false == true
    at PartyInternal.getPropertiestItem (webpack-internal:///../../../sdk/node_modules/@dxos/echo-db/dist/src/parties/party-internal.js:118:25)
    at Party.getProperty (webpack-internal:///../../../sdk/node_modules/@dxos/echo

The attempt at awaiting party open:

await party.activate({ global: true });
await party.open();

Results in the call to party.open() hanging forever.

telackey commented 3 years ago

The party is already open after calling party.activate. Calling party.open again shouldn't hang, but it isn't proper either.

The problem in this case is that party.getPropertiesItem() looks like this:

  getPropertiestItem (): Item<ObjectModel> {
    const { value: items } = this.database.queryItems({ type: PARTY_ITEM_TYPE });
    assert(items.length === 1);
    return items[0];
  }

But just because the Party is open does not mean that item has been processed, and in fact that item will never be processed until after the Party is open.

So the fix is to wait on that item, either here, or by changing this into a result set we can wait on, or if we really want to, by waiting for it at the end of party.open, so we don't return until after this has been processed.

telackey commented 3 years ago

@rzadp ^^

rzadp commented 3 years ago

by waiting for it at the end of party.open, so we don't return until after this has been processed

I think this might be the best solution, especially given that we have already run into this problem before - https://github.com/dxos/echo/issues/311