Node.bcrypt.js: app is crashing while using bcrypt's async methods

Created on 12 Nov 2018  路  22Comments  路  Source: kelektiv/node.bcrypt.js

app is crashing while using bcrypt package in the app, to test it separately I put the code in a separate file as below.
1) tried to put the constant (10) value in the hash function instead of getting in getSalt function.
2) tried to catch the error in different ways but not getting any error.
3) if I comment the bcrypt function then everything else (if I have anything) working fine in the function.

    const bcrypt = require('bcrypt');
    async function run(){
    const saltValue =await bcrypt.genSalt(10);
    bcrypt.hash('12345',saltValue)
    .then(result => console.log(result))
    .catch(error => console.log(error));
    }
    run();

Version: node : 9.0.0 npm: '5.5.1' "bcrypt": "^3.0.2"
OS: Windows 7.

Most helpful comment

For "bcrypt": "^3.0.2", Upgrading to Node v10 solved the problem for me.

All 22 comments

The app is crashing for asynchronous functions only.
I tried to use synchronous functions and it is working fine.

const saltValue = bcrypt.genSaltSync(10);
const hashed = bcrypt.hashSync('12345',saltValue);

Please give the error message

executing it with node is not giving any output, but nodemon is showing it as app crash.

bcrypterror

And changing it with the synch methods successfully giving the output.
bcryptsyncsuccess

Try to run without nodemon and post the error. You may be hitting an unhandled promise rejection error

With node it is not giving any output:
bcryptwithnode

I wish I had that unhandled promise error but it is not giving anything.
Just to debug it more I tried below code with more edge cases.

const bcrypt = require('bcrypt');
async function run(){
    try{
    console.log('beforeTest');
    const saltValue = await bcrypt.genSalt(10);
    const hashed = await bcrypt.hash('12345',saltValue);
    console.log(hashed);
    console.log('test');
}
catch(error)
{
    console.log(error);
}
console.log('AfterTest');
}
run();

And the output is:

bcryptdebug

can confirm the above behaviour on windows 10. both on node 8.9.2 and 10.13.0 using 3.0.2
On linux (suse and ubuntu) it works fine.
Reverting to 3.0.0 works for me at the moment.

@AyKarsi, I have tried on Windows 7 with node 9.0.0 only and it is working only for synchronous methods, not for asynchronous.

Strange, I do not find that behavior on Windows 10 and Node 8 or Node 11

@manishmawat
I tried Bcrypt 3.0.2 in Windows 7 with Node 8.9.1 and using async methods made my app(express server) crash.
Using [email protected] works fine, async and sync methods works.
npm i --save --save-exact [email protected]
It made me stick to use [email protected] since [email protected] crashed on my node 8.9.1
Hope that helps.

(Edited: Sorry for the mistake it was bcrypt-3.0.2 and not bcrypt-3.0.1)

For "bcrypt": "^3.0.2", Upgrading to Node v10 solved the problem for me.

Looks like the resurfacing of a similar error for NodeJS in OSX. The ABI compatibility of NodeJS is horrible. I'm still investigating a fix

Having the same problem, using Windows 10 with Node v8.9.4

same problem, using archlinux with node v8.9.2

This thing keep silently crashing my app.

I mean "silently terminating", because that's the real term, callback simply isn't called.

Should be fixed with new version and using a NodeJS version other than v8.9.x

I had the same issue with Node.js version 8.9.4 and I successfully fixed the issue with installing recommended version of bcrypt based on my Node.js version

I fixed the issue with [email protected]

Important note: Before you install bcrypt, first check version of Node.js on your machine, and based on that, install appropriate version of bcrypt

nodeversion

@mijatovicmile All versions >= 1.0.3 are compatible with NodeJS 8 except v8.9.x that minor version is problematic.

Encountered this today while running inside Docker. In my case this was caused by using node:lts-slim during build, and then copying the artifacts over to a node:lts-alpine-based image. As these two variants use different libc implementations, native libs built with either may not work with the other.
It's a mistake I've made in my Dockerfile, of course, but I wish I had received at least some hint as to what could be causing this, rather than the Node runtime just terminating like this 馃槀 (not bcrypt's fault)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

japita-se picture japita-se  路  4Comments

CMatias picture CMatias  路  4Comments

thorlacius picture thorlacius  路  4Comments

CQzhangshuai picture CQzhangshuai  路  5Comments

enneid picture enneid  路  5Comments