pouchdb-community / pouchdb-all-dbs

allDbs() plugin for PouchDB
Apache License 2.0
29 stars 18 forks source link

Race condition #5

Open nolanlawson opened 10 years ago

nolanlawson commented 10 years ago

I am 99% sure there is a race condition in this module. If you run npm run test-pouchdb in pouchdb-server enough times, you'll see stuff like this:

Possibly unhandled Error: database is closed
    at applyNextDocCountDelta (/Users/nolan/workspace/pouchdb-server/node_modules/pouchdb/lib/adapters/leveldb.js:120:28)
    at incrementDocCount (/Users/nolan/workspace/pouchdb-server/node_modules/pouchdb/lib/adapters/leveldb.js:142:5)
    at countDocs (/Users/nolan/workspace/pouchdb-server/node_modules/pouchdb/lib/adapters/leveldb.js:107:14)
    at PouchAlt.LevelPouch.api._info (/Users/nolan/workspace/pouchdb-server/node_modules/pouchdb/lib/adapters/leveldb.js:154:5)
    at PouchAlt.<anonymous> (/Users/nolan/workspace/pouchdb-server/node_modules/pouchdb/lib/adapter.js:666:8)
    at PouchAlt.<anonymous> (/Users/nolan/workspace/pouchdb-server/node_modules/pouchdb/lib/utils.js:443:21)
    at PouchAlt.<anonymous> (/Users/nolan/workspace/pouchdb-server/node_modules/pouchdb/node_modules/argsarray/index.js:14:18)
    at /Users/nolan/workspace/pouchdb-server/node_modules/pouchdb/lib/utils.js:405:21
    at tryCatch2 (/Users/nolan/workspace/pouchdb-server/node_modules/pouchdb/node_modules/bluebird/js/main/util.js:73:19)
    at Promise$_resolveFromResolver [as _resolveFromResolver] (/Users/nolan/workspace/pouchdb-server/node_modules/pouchdb/node_modules/bluebird/js/main/promise.js:595:13)
gr2m commented 7 years ago

despite the issue being old, just want to mention that the problem here is that this module executes asynchronous code in event handlers: https://github.com/pouchdb-community/pouchdb-all-dbs/blob/a90d0b16be187a37e15e6dd95f40f79d0cb96506/lib/index.js#L57-L105 This is what can cause race condition