Node.bcrypt.js: bcrypt crashes in child process

Created on 8 Mar 2019  ·  22Comments  ·  Source: kelektiv/node.bcrypt.js

If you are trying to load bcrypt in child process (worker thread) it will fail with the error:
~
Error: Module did not self-register.
at Object.Module._extensions..node (internal/modules/cjs/loader.js:779:18)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Module.require (internal/modules/cjs/loader.js:667:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (O:\Texts\Sources\my\bcrypt-shild-process\node_modules\bcrypt\bcrypt.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Module.load (internal/modules/cjs/loader.js:630:32)
~

Info:
-

  • Node v11.10.0
  • bcrypt v3.0.4

I've created sample project for this issue: https://github.com/Suvitruf/bcrypt-child-process-crash-proof

bug

Most helpful comment

@khangaridb You can use the napi variant of the module. npm i bcrypt@napi

The primary module will be compatible in few days, I did some initial work and it needs some polish before I can publish

All 22 comments

What would be the output if it runs?

Can you try experimenting with the n-api version of the module? npm i bcrypt@napi

I've updated my repo. The output should be:

I'm ok, because I'm alpha main
same
I'm sad, because I can't load bcrypt
same

Same problem with n-api version.

child_process is not same as worker_thread. I guess, we have some issues when multiple threads try to access native libraries.

In my system (Ubuntu 18.04, Node 11.11.0), napi crashes without any error message

Edit: actually does not crash and instead works fine.

09:07:49 PM IST | amitosh ❱ bcrypt-child-process-crash-proof ❱
❱ node index.js 
I'm ok, because I'm alpha main
same
I'm sad, because I can't load bcrypt
same

I'm running it on Windows 7.

Here's my code after NAPI modifications: https://github.com/agathver/bcrypt-child-process-crash-proof/tree/napi

I would need to catch hold of a Windows machine to test this.

I saw worker_threads are still marked as experimental, and we have warnings about using native modules in electronjs Web workers. Perhaps there may be some bugs in the implementation.

I saw worker_threads are still marked as experimental

Yeh, but recently they said that it's kinda stable right now: https://github.com/nodejs/node/pull/25361. You don't even need to use --experimental-worker flag anymore.

I everyone the problem here is that when you use worker-threads the addon will be loaded multiple times in multiple contexts and to allow this the addon must support multiple initializations.
My opinion is he it's necessary to modify brcypt to be a context aware addon.
@agathver @Suvitruf What do you think about this? Do you agree to apply this change?

@NickNaso good idea. But I'm not familiar with native modules =/

@NickNaso The module uses no static variables, this change should be trouble free. We need to add a new worker_threads test case too.

If it's ok for you I will try to work on this issue and solve the problem.

Sure go ahead. AFAIK, there are only a few lines of change at bcrypt_node.cc

And the napi version already works out of the box with worker_threads

On Tue, Mar 26, 2019 at 2:42 PM Nicola Del Gobbo notifications@github.com
wrote:

If it's ok for you I will try to work on this issue and solve the problem.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/kelektiv/node.bcrypt.js/issues/709#issuecomment-476536206,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQCaT2VBYoVyp5DTHKQNtmdTXCq2q61Kks5vaeSagaJpZM4bk32G
.

@NickNaso Let me know if you will be able to work on the issue. It's a minor change. Else I would go ahead and publish the version myself

@agathver if you want go to work on the issue. Unfortunately I had not time last week.

Any updates on this issue?

@khangaridb You can use the napi variant of the module. npm i bcrypt@napi

The primary module will be compatible in few days, I did some initial work and it needs some polish before I can publish

You can use the napi variant of the module. npm i bcrypt@napi

Which version? ^3.0.6-napi doesn't work on Windows.

napi is 3.0.4, it doesn't quite track mainline bcrypt yet

I have this same problem on windows 10. Any update?

I have this problem too, even with the napi one, any update?

Can you check if v4 solves your problem?

@agathver The version 4 is not published on npm, but only available on GitHub.

@agathver The version 4 is not published on npm, but only available on GitHub.

Now is on npm Thanks to everybody.

Was this page helpful?
0 / 5 - 0 ratings