kelektiv / node.bcrypt.js

bcrypt for NodeJs
MIT License
7.4k stars 512 forks source link

libc++abi: terminating with uncaught exception of type Napi::Error #980

Closed olalonde closed 1 year ago

olalonde commented 1 year ago

I'm getting a very weird and difficult to reproduce bug...

The process exits with this:

libc++abi: terminating with uncaught exception of type Napi::Error

It happens when I forgot await the compare() promise, e.g.:

async function assertPasswordMatches(plaintextPassword: string, hash: string) {
  const matches = /* oops forgot await */ bcrypt.compare(plaintextPassword, hash);
  if (!matches) {
    throw new AuthError();
  }
}

The bug happens when I running a test using vitest. I tried to reproduce in the node.bcrypt.js test files but didn't manage to. :/

bcrypt 5.1.0 node v18.8.0 MacOS M1

olalonde commented 1 year ago

Oh, it seems it had to do with vitest's multithreading. I tried to reproduce with vitest --no-threads and the issue is gone. Vitest uses https://github.com/tinylibs/tinypool to achieve multithreading. JavaScript doesn't support multithreading so I'm not sure what's going on here. Maybe it's not an important bug to fix.

olalonde commented 1 year ago

Also getting the same issue with argon2 so likely not fixable by this package.

recrsn commented 1 year ago

It's due to how we handle Isolates inside Napi::AsyncWorkers, a fix of that is out of scope for us, something Node should fix