-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: Race condition for pouchdb hanging indefinitely when multiple instances are used #8513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Race condition for pouchdb hanging indefinitely when multiple instances are used #8513
Conversation
This is a simple repro for a problem discovered in PouchDB 7.3.0. This was originally discovered in RxDB. Discussion here: pubkey/rxdb#3807. ``` 134 passing (2s) 3 pending 1 failing 1) test.memory-adapter.js Race condition initially discovered with PouchDB in-memory-adapter 7.3.0: Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. at listOnTimeout (node:internal/timers:559:17) at processTimers (node:internal/timers:502:7) ```
dfd0e49 to
d04021f
Compare
|
I've updated my PR:
Hope this gets included into a future release! 🤞🏼 |
garethbowen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the test, that's really helpful. I've added a suggestion.
| var adapterName = functionName(leveldown); | ||
| var adapterStore = dbStores.get(adapterName); | ||
| var keys = [...adapterStore.keys()].filter(k => k.includes("-mrview-")); | ||
| var keys = [...adapterStore.keys()].filter(k => k.includes(name)).filter(k => k.includes("-mrview-")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a small issue here if you have two dbs with the same prefix, for example, "test-db" and "test-db-2". If you close "test-db" the same race condition will occur. I think we can make the matching string more restrictive to avoid these edge cases, eg:
| var keys = [...adapterStore.keys()].filter(k => k.includes(name)).filter(k => k.includes("-mrview-")); | |
| var viewNamePrefix = PouchDB.prefix + name + "-mrview-"; | |
| var keys = [...adapterStore.keys()].filter(k => k.includes(viewNamePrefix)); |
You'll have to import PouchDB too, and I haven't actually run this code, but I think it'll work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking this over! Ran this locally and it seemed to work. Updated the tests and used the code snippet you provided. Just pushed the commit. CI should complete in about 10 minutes to verify.
garethbowen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
…ly when multiple instances are used" This reverts commit 24157fc.
Release notes: https://github.com/pouchdb/pouchdb/releases/tag/8.0.0 It includes a fix for our issue with multiple PouchDB instances used concurrently, see: apache/pouchdb#8513. Also note that we are waiting for a clarification about the way dependent databases are handled in PouchDB. This could lead to new changes, see: apache/pouchdb#8574. We still allow compat with versions >= 7.2.2 < 7.3.0 for ease of use alongside previous Tanker SDK versions that required these versions. We ban the 7.3.x versions though since they are affected by the aforementioned bug.
This is a self-contained repro for a problem discovered in PouchDB 7.3.0 where 2 databases using the
memoryadapter could impact each other and ultimately become non-responsive.This was originally discovered in the RxDB test suite. Discussion here: pubkey/rxdb#3807.