-
Notifications
You must be signed in to change notification settings - Fork 44
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
Module does not self-register lmdb-store.node #67
Comments
Do you know how you are restarting the node process? Is it completely killing the process and restarting it? I think chokidar is just responsible for file watching, not restarting. I did update the code to use the latest recommended node add-on API and published as part of v1.6.0-beta.1 if you want to try that and see if it makes a difference? |
I am using worker_thread.terminate() method to kill the process. Ok, will try tomorrow maybe. I just switched using sqlite for meantime... |
So the way I run lmdb-store is like this:
Main process will restart db worker thread on file change |
I have not been able to reproduce this while terminating and starting new threads. Does it make any difference if the main process has loaded/required lmdb-store (I think there can be a different cleanup procedure if the module is still in use)? Also what version of node is this? |
This is latest node v.16.4.0, Yeah now it's intermitently terminated. On a bad day, almost every reload is terminated. |
FWIW, I use esbuild to build my ts source file, and then run resulting build file using worker_threads. So I execute different source code for each run (esbuild generate new file whenever file changes) |
When I use node-lmdb on main, it's running smooth. But, I really need to run node-lmdb on worker_thread because we have several thread to process different database, and can kill it whenever we need without interupting main process. Also we use worker_thread because we can just postMessage when we thread needs to coordinate each other. |
What I meant was if you could just load lmdb-store in the main thread and still use lmdb-store in the worker threads as you are currently doing. It sounds like you have probably already tried that though. I have tried reproducing this on multiple machines now, including on Windows, Mac, and Linux without any issues or success in reproducing this. I suppose it is possible it is related to M1 (I don't have access to an M1 Mac right now). I have previously observed an issue (#48 ) with M1's apparently having different timing with threads resuming after a mutex unlocks, and node does use mutexes for add-on registration (and threads and non-determinism also are at play). However, that seems like it would affect (all?) other native add-ons running on Node + M1, which seems unlikely to me (surely someone else would have noticed). Is it possible for you to test if this does affect any other native add-ons? lmdb-store should transitively depend-on/install msgpackr-extract, maybe you see if this error occurs if your worker threads load/require the msgpackr-extract package (or other native add-on packages)? Or if you have any test case that I can run, that would certainly be welcome also. Anyway, your setup is very legitimate way of running lmdb-store (we basically do the same exact thing in our medical software, except we use processes instead of threads), so I definitely would like to get it fixed. |
Well. yeah, M1 support is definitely flaky on npm, so my choices is limited and the best I can do is report like this. It would take me a while to set up a test case. My hand is currently full, my team already past the deadline -- sorry! I will report back to you when I can touch this issue again. |
I have this problem, too, when using parcel 2.0.0+ OS: 5.4.0-89-generic #100-Ubuntu SMP, Ubuntu 20.04 It was not resolved by:
|
@hgeist2 Are you getting a "symbol not found" error or a "Module does not self-register" error? |
@kriszyp: Its the "Module does not self-regitser" one Error: Module did not self-register: '/home/.../node_modules/lmdb-store/build/Release/lmdb-store.node'. |
Do you have any ideas if there is any other parcel configurations that are likely to help reproduce this? I have a ubuntu box here I can install parcel on and try, but I'm guessing that parcel folks at least tested the basic parcel+ubuntu combination before releasing. Anyway, I would love to be able to track down this mysterious bug though. |
I will share with you as much as i can. I read somewhere that parcel-cache uses lmdb-store. The repo also uses git submodules. Full Stack trace: Error: Module did not self-register: '.../node_modules/lmdb-store/build/Release/lmdb-store.node'. package.json
babel.config.json
|
Thank you for the details! I'll see if I can reproduce. |
@hgeist2 I was able to start this right up with your config files and just adding a index.pug, and it all ran perfectly fine for me on my linux mint computer. Based on previous comments, it sounded like this had something to do with workers/threads, is it possible that there is something that triggers multiple threads to start in parcel in your setup? And this a consistent error, or intermittent? |
By default, Parcel uses worker threads. You can override the automatic calculation with |
Turns out updating to node 15.x/15.4 solves the problem. |
Hmm, that's interesting. Node 15.x isn't really supported (by NodeJS, only 12.x, 14.x, 16.x, and 17.x are the maintained/supported versions). And the OP was using Node 16.x. I wonder if this goes away on a newer 16.x as well? And my attempts to reproduce this were with Node 14.17.3. And I did actually try |
If i switch to 16.13.0 it stops working and if i switch back to 15.4.0 it starts working again. Im not sure PARCEL_WORKERS=x really does anything in parcel 2.0.0, i could not find anything in the docs about it. |
The project leader downloaded and tried to compile lmdb-store locally. That went fine, but the tests failed. Maybe both stacktraces stem from a problem with type casting? Could be confirmed if the test below starts working on 15.4.0
|
Sorry for the spam. I downloaded lmdb-store 1.6.11. and ran npm test
That is directly inverted to the self-register stacktrace and node relationship. |
I appreciate it, would love to track this down! So I believe the type casting stacktrace is specific to running the debug builds (in combination with some specific node version and OS, I assume, since I haven't seen it before), which are only run by default with I tried your app/config specifically with node v14.15.4 and v16.13.0, and still didn't see any self-register error. I noticed in the other stack trace that it is ARM64; are you on ARM64 too? That might be an interesting bit of commonality with the OP. |
I am on x64 / Ryzen. The other stacktrace with ARM64 is a new M1 Mac |
Self-register stacktrace prevails on 5.4.0-89-generic #100-Ubuntu SMP, Ubuntu 20.04, x64 Ryzen as above with the following node versions:
Only 15.4.0 works and i can reproduce it. Installations via nvm. https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V15.md#15.4.0 |
Are you recompiling with each of these nvm changes? I actually can reproduce this self-register error message by deleting/renaming my prebuilds, compiling with one node version, and then switching to a different node version (with nvm as well). This is because the compiled code is for the wrong node version. This doesn't happen if your app is using the prebuilds, since switching node versions just ends up selecting a different/appropriate prebuild. I am guessing what happened is that lmdb-store got compiled/built on a node version that doesn't have a prebuild, specifically a v15.x version (I don't include prebuilds for the v15.x line because they aren't supported/maintained by NodeJS). And once lmdb-store gets compiled/built, it uses the locally compiled version over the prebuilds, and so even when you switch node versions, the locally compiled version gets used instead of the appropriate prebuild. What I don't understand is why v15.x versions would be incompatible with each other, since all 15.x versions are supposed to be on the same ABI. So I guess the questions is if this error still occurs if lmdb-store is re-installed/compiled with the node version that is currently being used? Or if it occurs with one of the prebuilds (using node 14.x or 16.x with the build/Release directory deleted/renamed)? |
That doesnt seem to be it. Shuffling the node js versions between 14.x, 15.x and 16.x and always deleting node_modules/ + npm i after each version switch still leads to same results. |
Did you happen to notice if it is compiling/building for all the different node js versions (versus using the prebuild, which shouldn't involve any compiling or any files created in build/Release)? I am just curious if there are possibly any differences between locally compiled and prebuilds in regards to this. |
My coworker said they didnt have problem with other parcel 2.0.0 projects and any kind of machine, be it mac m1, windows 10 or mint linux. It seems to be specific to my system. Some recompiling was done compiling cpp files for lmdb, but i did not watch closely. Will retry again tonight / next days |
Maybe this could be relevant to you? https://stackoverflow.com/a/41283828 I searched lmdb-store repo for NODE_SET_METHOD and NODE_MODULE without results. Maybe it solves automagically if you provide this initialization method additionally to NODE_MODULE_INITIALIZER in node-lmdb.cpp in case some packer like parcel does something weird or use NODE_MODULE_INIT instead of NODE_MODULE_INITIALIZER like they show in their example. https://nodejs.org/api/addons.html#addons_context_aware_addons If you provide me with the code i could try a build like that on my machine. |
…actically acceptable target name, and some crude logging, #67
You can't use NODE_MODULE and NODE_MODULE_INIT, since they both are defining the same function (_module), so they conflict. And using NODE_MODULE instead of the context-aware initializer doesn't work with worker threads (it will throw the self-register error the first time a worker thread tries to load it). However, in the latest commit, I did try a few things: I switched from NODE_MODULE_INITIALIZER to NODE_MODULE_INIT. I had tried this before and it didn't work, causing compilation errors. I realized this is because the build target name had a dash in it, and the macro was directly copying the target name into the source. I fixed this by change the build target name (to just "lmdb"). With this, I was able to switch to the more standard NODE_MODULE_INIT. I added some crude logging that can be enabled with I also saw a note in the SO post about having the registration module be the first in the list of sources. I have never heard that before, but figured I would try that as well. I did also include a commented-out sample code that use This update is in |
Thank you for the fast solution, i will try to build it from master and then give you feedback. |
I have this same issue with node v17.0.1 and npm 8.1.0 running on Pop!_OS 21.04. My project only has these dependencies and the error is originating from v8-compile-cache
|
@vozeldr Do you happen to know if lmdb-store compiled a build (created a node_modules/lmdb-store/build/Release, otherwise it is using the prebuilds)? |
Yes, sorry for not providing better initial info... That folder does exist. I only encounter this problem on subsequent builds and only "occasionally". When I get this error, I delete node_modules and reinstall and it works for a random time (it could be 1 or 2 builds, it could be a day's worth of builds). I only started encountering this problem after updating to the "new parcel", but it's been a consistent issue since then. |
So parcel/lmdb-store will work for a while, and then start throwing this error, and that point it will just continue to throw this error until you reinstall all the packages? Any chance you could see if it is resolved with the latest updates on master? |
I can confirm that the latest master solves the issue. Moved project to a new VM which was based on Xbuntu 20.04, too. Got the same error with install from the repo and it was fixed by installing the current master. |
Thank you so much for checking this out @hgeist2! I have published v1.6.12 with this fix. If anyone else is able to try that out, would love to know if fixes the other situations where this occurs. |
I am using lmdb-store with chokidar and restart node proces when my source file changes. At first lmdb-store runs fine, and then I got this error when live-reload occured:
I am using macbook m1 fwiw, is there anything I can do to solve this ?
The text was updated successfully, but these errors were encountered: