Skip to content

Conversation

@PaulMest
Copy link
Contributor

This PR contains:

  • IMPROVED TESTS

Describe the problem you have without this PR

PouchDB 7.3.0 introduced a race condition where two databases open in memory at the same time could cause hanging conditions. This was initially discovered randomly by 2 tests in the test suite. This PR adds a smaller consolidated view of this race condition.

Simple repro:

$ npm install
$ npm run test:fast:pouchdb

Todos

  • Changelog
  • Actual fix

simple repro:
```
$ npm install
$ npm run test:fast:pouchdb
```
@cetsupport
Copy link

cetsupport commented May 27, 2022

@PaulMest Looks like there have race condition when close one of multiple database.

When execute db.close, will call pouchdb-adapter-leveldb-core/lib/index.js:
From line 1218:

  api._close = function (callback) {
    /* istanbul ignore if */
    if (db.isClosed()) {
      return callback(pouchdbErrors.createError(pouchdbErrors.NOT_OPEN));
    }
    db.close(function (err) {
      /* istanbul ignore if */
      if (err) {
        callback(err);
      } else {
        dbStore.delete(name);

        var adapterName = pouchdbUtils.functionName(leveldown);
        var adapterStore = dbStores.get(adapterName);
        var keys = [...adapterStore.keys()].filter(k => k.includes("-mrview-"));
        keys.forEach(key => {
          var eventEmitter = adapterStore.get(key);
          eventEmitter.removeAllListeners();
          eventEmitter.close();
          adapterStore.delete(key);
        });

        callback();
      }
    });
  };

The problem happen in below line:

        var keys = [...adapterStore.keys()].filter(k => k.includes("-mrview-"));

So when we close first database, actually will select the second database views... and disconnect it. This cause problem from my point of view.

I will submit a PR to pouchdb.

@pubkey
Copy link
Owner

pubkey commented Aug 16, 2022

I am closing this issue here because there is nothing that can be done on the RxDB side. I will reopen when it is fixed on the pouchdb side.
Related links:
apache/pouchdb#8515
apache/pouchdb#8513

@pubkey pubkey closed this Aug 16, 2022
@PaulMest
Copy link
Contributor Author

apache/pouchdb#8513 has been merged. The fix should be in the next version of PouchDB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants