Skip to content
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

app is crashing while using bcrypt's async methods #674

Closed
manishmawat opened this issue Nov 12, 2018 · 26 comments
Closed

app is crashing while using bcrypt's async methods #674

manishmawat opened this issue Nov 12, 2018 · 26 comments

Comments

@manishmawat
Copy link

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.

@manishmawat manishmawat changed the title app is crashing whi;e using bcrypt app is crashing while using bcrypt Nov 12, 2018
@manishmawat
Copy link
Author

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);

@manishmawat manishmawat changed the title app is crashing while using bcrypt app is crashing while using bcrypt's async methods Nov 12, 2018
@recrsn
Copy link
Collaborator

recrsn commented Nov 12, 2018

Please give the error message

@manishmawat
Copy link
Author

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

@recrsn
Copy link
Collaborator

recrsn commented Nov 12, 2018

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

@manishmawat
Copy link
Author

manishmawat commented Nov 12, 2018

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

@AyKarsi
Copy link

AyKarsi commented Nov 14, 2018

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.

@manishmawat
Copy link
Author

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

@recrsn
Copy link
Collaborator

recrsn commented Nov 18, 2018

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

@markterence
Copy link

markterence commented Nov 27, 2018

@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 bcrypt@2.0.1 works fine, async and sync methods works.
npm i --save --save-exact bcrypt@2.0.1
It made me stick to use bcrypt@2.0.1 since bcrypt@3.0.2 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)

@recrsn
Copy link
Collaborator

recrsn commented Nov 27, 2018

@markterence
Copy link

Hi, here is the zipped crashdump using DebugDiag.

https://www.dropbox.com/s/om6aszrmju1bfbo/FullCab_Date__11_28_2018__Time_09_27_33AM_1.cab?dl=0

@raugaral
Copy link

Solution here:
#664 (comment)

@tech-engine
Copy link

tech-engine commented Dec 2, 2018

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

@recrsn
Copy link
Collaborator

recrsn commented Dec 2, 2018

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

@callmeteus
Copy link

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

@Dandan1314
Copy link

same problem, using archlinux with node v8.9.2

@e-gautier
Copy link

This thing keep silently crashing my app.

@e-gautier
Copy link

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

@recrsn
Copy link
Collaborator

recrsn commented Mar 1, 2019

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

@recrsn recrsn closed this as completed Mar 1, 2019
@ghost
Copy link

ghost commented Mar 30, 2019

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 bcrypt@2.0.1

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

@recrsn
Copy link
Collaborator

recrsn commented Mar 31, 2019

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

@gdrbyKo1
Copy link

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)

@agonyz
Copy link

agonyz commented Aug 23, 2023

@gdrbyKo1 Thank you mate, you really saved me there!

I was having the exact same problem and could not figure out was wrong since my nestjs logs inside the docker container did not show anything :D

@EdgarAlonsoPerez
Copy link

EdgarAlonsoPerez commented Oct 16, 2023

I've run into a similar problem. My NestJS app functions fine locally, but when I moved it to a Docker container and attempted to invoke 'bcrypt' with version 5.1.1, it caused issues. Initially, I was using the 'node:alpine' image, but after switching to 'node' everything seems to be working smoothly now.

@rsedaaghi
Copy link

I've run into a similar problem. My NestJS app functions fine locally, but when I moved it to a Docker container and attempted to invoke 'bcrypt' with version 5.1.1, it caused issues. Initially, I was using the 'node:alpine' image, but after switching to 'node' everything seems to be working smoothly now.

Thanks I ran into the same problem and as @EdgarAlonsoPerez said using bcrypt 5.1.1 with node instead of node:alpine solved the problem.

@JordiBustos
Copy link

I've verified that using bcrypt 5.1.1 with Node.js 21 on Alpine 3.18 leads to a crash without any specific error. However, when I switched to the Node.js 21 slim variant, the issue was resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests