-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
infinite loop with crypto.randomBytes() causing 100% CPU hang #813
Comments
For reference, the equivalent async program runs fine: var crypto = require('crypto')
;(function f() {
crypto.randomBytes(32, function(err, bytes) {
if (err) throw err
console.log(bytes.toString('hex'))
f()
})
})() |
It actually appears to hang outside the var crypto = require('crypto')
for (var i = 0;; i++) {
console.log(i + '+')
crypto.randomBytes(32)
console.log(i + '-')
} This always hangs at a |
What sort of system are you running on? |
@nathan7 , I do not understand what do you expect from an infinite loop, calling synchronously and indefinitely |
Please see the note here: https://iojs.org/api/crypto.html#crypto_crypto_randombytes_size_callback Your process is blocking and stalling because you are infinitely looping over it. |
I can get plenty of entropy from /dev/random with other methods, without getting 100% CPU usage. |
@nathan7 , please try this code on your machine: while (true) {
console.log('1234567890');
} and make your conclusions, the problem is not in |
Does |
@Fishrock123 |
@nathan7 an infinite loop will... infinitely loop. As fast as possible. I'm not really sure what you expect..? Type |
@Fishrock123 |
The process prints a bunch of random numbers (yay!) and then hangs badly (:cry:) at 100% CPU.
I'm not sure how to debug this.
The text was updated successfully, but these errors were encountered: