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

Weird behaviour of verify() with setTimeout() #25

Closed
julien-f opened this issue Feb 24, 2016 · 9 comments
Closed

Weird behaviour of verify() with setTimeout() #25

julien-f opened this issue Feb 24, 2016 · 9 comments
Labels

Comments

@julien-f
Copy link

The promise returned by verify() does not resolve before the first timer is up.

Steps to reproduce

// Without this line, verify() takes about 50ms to complete, with it, it takes 1 second.
setTimeout(function () {}, 1e3)

console.time('verify()')

require('argon2').verify('$argon2i$m=4096,t=3,p=1$tbagT6b1YH33niCo9lVzuA$htv/k+OqWk1V9zD9k5DOBi2kcfcZ6Xu3tWmwEPV3/nc', 'password')
  .then(function () {
    console.timeEnd('verify()')
  })

Environment

Operating system: Debian Stretch
Node version: 4.3.0

@ranisalt
Copy link
Owner

It's not the first time I see this issue, which seems to be an issue with v8. Apparently, it happens the promise resolve/reject call happens on the next tick of the Node event loop, but setTimeout extends this tick until it the timeout is reached, and only then the event loop ticks.

There seems to be some workarounds for this but they are really weird and probably not worth the trouble. Care to share a real example where it is an issue?

@ranisalt
Copy link
Owner

Marked as wontfix at least until there's a clarification on why this happens by v8.

@julien-f
Copy link
Author

I don't know where it comes from, this issue does not appear when using promises directly, neither combine with setImmediate()/setTimeout() or process.nextTick():

setTimeout(function () {}, 1e3)

console.time('Promise.resolve()')
Promise.resolve()
  .then(function () {
    console.timeEnd('Promise.resolve()')
  })
// → Promise.resolve(): 4ms

console.time('setImmediate()')
new Promise(function (resolve) { setImmediate(resolve, 0)})
  .then(function () {
    console.timeEnd('setImmediate()')
  })
// → setImmediate(): 7ms

console.time('setTimeout()')
new Promise(function (resolve) { setTimeout(resolve, 0)})
  .then(function () {
    console.timeEnd('setTimeout()')
  })
// → setTimeout(): 7ms

console.time('process.nextTick()')
new Promise(function (resolve) { process.nextTick(resolve)})
  .then(function () {
    console.timeEnd('process.nextTick()')
  })
// → process.nextTick(): 4ms

This behavior currently breaks my tests.

@ranisalt ranisalt added bug and removed wontfix labels Feb 26, 2016
@ranisalt
Copy link
Owner

Oh, I see in your tests this is behavior for 0.9.x, I'll look at the changes from 0.8 and see what possible broken.

@julien-f
Copy link
Author

julien-f commented Apr 3, 2016

Is there any news regarding this issue?

If it's completely broken in C++, maybe you should create promises in the JS wrapper…

@ranisalt
Copy link
Owner

ranisalt commented Apr 7, 2016

Locally it worked properly, and I added a timeout test to prevent regression in the future. Could you check?

(sorry for the delay, life's a bit rushing)

@julien-f
Copy link
Author

julien-f commented Apr 7, 2016

I don't seem to be able to build the package from the git repo:

$ npm i

> argon2@0.10.0 install /tmp/hashy/node_modules/argon2
> node-gyp rebuild

make: Entering directory '/tmp/hashy/node_modules/argon2/build'
make: *** No rule to make target 'Release/obj.target/libargon2/argon2/src/argon2.o', needed by 'Release/obj.target/argon2.a'.  Stop.
make: Leaving directory '/tmp/hashy/node_modules/argon2/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 4.2.0-1-amd64
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /tmp/hashy/node_modules/argon2
gyp ERR! node -v v4.4.1
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok 

@ranisalt
Copy link
Owner

ranisalt commented Apr 7, 2016

You don't have the submodule. Clone with --recursive or run git submodule update --init.

@julien-f
Copy link
Author

julien-f commented Apr 7, 2016

My bad :)
Maybe it could be in the README ;)

It works! Thanks for the fix.

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

No branches or pull requests

2 participants