rafamel / rxdb-utils

RxDB's missing pieces
MIT License
69 stars 5 forks source link

When replication fails to initiate it does so silently #8

Open motin opened 5 years ago

motin commented 5 years ago

Version: 2.0.0-beta1

During local testing I have had to reset the database sometimes. Sometimes this includes deleting and recreating the couchdb replication database (or else all the previous data would be replicated back into the reset local database). While my app has three collections that ought to be replicated upon replicate(), I have noticed that none or only a few of them gets replicated sometimes.

There is no log output informing about connectivity or replication issues, despite:

import { loglevel, loglevels } from "rxdb-utils/logger";
// Set log level for rxdb-utils plugins
loglevel(loglevels.TRACE);

Steps to reproduce

  1. git clone https://github.com/motin/cloudant-admin-cli
  2. stack/start.sh
  3. node index.js --create-db localdevtest
  4. Using a fresh RxDB database, replicate against http://localhost:8080/localdevtest/
  5. See that replication works as expected
  6. Remove and recreate the local RxDB database
  7. node index.js --reset-db localdevtest
  8. Using the new RxDB database, replicate against http://localhost:8080/localdevtest/

Expected results

Working replication, or at least errors informing about that the replication could not initiate.

Actual results

No replication. No log output.

Notes

By using the following debug code...

      console.log("AppRxDatabase: sync - dbSyncUrl: ", dbSyncUrl);
      await appRxDatabase.replicate(dbSyncUrl).connect();
      console.log("Replications: ", appRxDatabase.replications);
      const replicationStates = appRxDatabase.replications[0].replicationStates;
      console.log("replicationStates: ", replicationStates);

I can confirm that none or only a few collections gets replicated:

    collections: { heroes: [RxCollection] },
    replicationStates: [ [RxReplicationState] ],

If all is well, I'd see three collections being replicated:

    collections:
     { heroes: [RxCollection],
       files: [RxCollection],
       financial_events: [RxCollection] },
    replicationStates:
     [ [RxReplicationState],
       [RxReplicationState],
       [RxReplicationState] ],

I can't use replicationState.error$, since it requires the existence of a replicationState.

rafamel commented 5 years ago

Hi Fredrik, thanks for reporting. When you reset the DB, do you also reload the process/page that is replicating against those DBs, or are you saying that when resetting the DBs, the connection doesn't recover while the same process as before stays open?

motin commented 5 years ago

My main concern is that it does not help reloading the process. It is less critical that it does not recover while the same process as before stays open.

Btw, the only workaround currently is to keep changing the database name, ie http://localhost:8080/localdevtest2/, http://localhost:8080/localdevtest3/ etc

rafamel commented 5 years ago

Hi Fredrik. Can you provide some example client repo that replicates the issue so I can test this more extensively?

motin commented 5 years ago

Sure, will do :)