leveldown: LevelDown version > `5.0.2` with PouchDB => MacOS crash with MaxListenersExceededWarning (once called more than once)
As reported in PouchDB: https://github.com/pouchdb/pouchdb/issues/7819 https://github.com/pouchdb/pouchdb/issues/7825 https://github.com/pouchdb/pouchdb/issues/7848
I narrowed-down the bug to the leveldown
transition from version 5.0.2
to 5.0.3
(ALL other package versions are latest
, currently levelup
= 4.3.2
, pouchdb-adapter-leveldb
= 7.1.1
, pouchdb-adapter-leveldb
= 7.1.1
, etc.)
In other words, ONLY leveldown
needs to be pinned to version 5.0.2
. In my case, the package.json
looks like:
"optionalDependencies": {
"leveldown": "5.0.2",
"pouchdb-adapter-leveldb": "^7.1.1"
},
"resolutions": {
"leveldown": "5.0.2"
}
LevelDown diff between version 5.0.2
and 5.0.3
:
https://github.com/Level/leveldown/compare/v5.0.2...v5.0.3
Note my app stacktrace:
Uncaught Exception:
Error: once called more than once
at /project/node_modules/pouchdb-core/node_modules/pouchdb-utils/lib/index.js:88:13
at /project/node_modules/argsarray/index.js:14:18
at /project/node_modules/pouchdb-core/lib/index.js:769:14
at /project/dist/node_modules/pouchdb-adapter-leveldb-core/lib/index.js:350:18
at /project/dist/node_modules/argsarray/index.js:14:18
at /project/dist/node_modules/pouchdb-adapter-leveldb-core/lib/index.js:429:16
at /project/dist/node_modules/sublevel-pouchdb/lib/index.js:243:9
at /project/dist/node_modules/sublevel-pouchdb/lib/index.js:74:13
So, I am not certain that the problem actually stems from the leveldown
implementation, but I thought I’d post this here as well as in the PouchDB issue tracker, just in case somebody here has a clue as to why the leveldown
code change introduced in version 5.0.3
trips the PouchDB LevelDB adapter.
I should point out that my app is built with Electron version 6.0.12
(NodeJS 12
), but I had the exact same problem with earlier Electron/NodeJS versions. LevelDown is built with npm rebuild --runtime=electron --target=6.0.12 --disturl=https://atom.io/download/atom-shell --build-from-source
.
Thank you!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 35 (24 by maintainers)
Commits related to this issue
- hotfix(dev): LevelDown versions in node_modules were only deduped at code level during NPM install, precompiled binaries of NodeJS plugins were loaded several times (Fixes #496 Also see https://github... — committed to edrlab/thorium-reader by danielweck 5 years ago
- Produce a unique namespace at compile time Closes #686. — committed to Level/leveldown by vweevers 5 years ago
- Try out -fvisibility=hidden for mac Ref #686, #687. — committed to Level/leveldown by vweevers 5 years ago
- Hide symbols on mac with -fvisibility=hidden (#688) Ref #686, #687. — committed to Level/leveldown by vweevers 5 years ago
It looks like you are on the right track! 😃
Meanwhile, I have found a better workaround that does not require pinning to version
5.0.2
. Instead I can just use the latest version (^5.3.0
) but I must make sure to delete the de-dupedleveldown
NPM package (./node_modules/pouchdb-adapter-leveldb/node_modules/leveldown
, which containsbuild/Release/leveldown.node
). It’s that simple 😃 Thanks for putting me on this track!This works:
This way symbols get prefixed with a versioned namespace.
Better yet, use random bytes, hex-encoded, so it always produces valid identifiers.
We sleep on it.
@vweevers There is a pattern between “newer version” vs “older version” above. Note that the version pairs
5.3.0
/5.0.2
too many5.0.2
/5.3.0
not calledbehave exactly the same as
5.0.3
/5.0.2
too many5.0.2
/5.0.3
not calledI’m betting you’ll get the same result if you replace
5.3.0
with5.2.0
or any other version over5.0.3
.I’m thinking it could be related to different class function memory layout, given that we have changed a bit how some methods are pure virtual, adding
DoComplete()
we might end up in a weird situation because we’re loading libraries dynamically and maybe messing around with function address space. I’m guessing very hand wavy here.This “MaxListenersExceededWarning” MacOS-specific definitely needs a minimal repro test-case. I am not sure what triggers this, I was hoping that the stack trace posted at the top of this comment thread would provide some clues.
I suspect that the issue filed here for
leveldown
can safely be closed, because the problem probably arises from how PouchDB integrates it. However I am very grateful for your replies, which have helped on multiple levels already.Cheers.