Should be possible to use `crypto.randomBytes`'s async API
See original GitHub issueRunning my program with --trace-sync-io
, I see:
WARNING: Detected use of sync API
at _rng (/home/blong/trello-idea-powerup/node_modules/node-uuid/uuid.js:60:53)
at v4 (/home/blong/trello-idea-powerup/node_modules/node-uuid/uuid.js:224:55)
// etc.
The problem is that you’re using crypto.randomBytes
synchronously, and don’t seem to provide a way to pass a callback and use the async API.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:16 (7 by maintainers)
Top Results From Across the Web
How to use async/await using crypto.randomBytes in nodejs?
Can anyone help me with this? All I'm trying to do is to get randomBytes async. using the async./await block but ensure that...
Read more >Crypto | Node.js v19.3.0 Documentation
It is possible for Node.js to be built without including support for the node:crypto module. In such cases, attempting to import from crypto...
Read more >Node.js crypto.randomBytes() Method - GeeksforGeeks
The crypto.randomBytes() method is used to generate a cryptographically well-built artificial random data and the number of bytes to be ...
Read more >Random - Expo Documentation
expo-random provides a native interface for creating strong random bytes. With Random you can create values equivalent to Node.js core crypto.randomBytes API.
Read more >Crypto.getRandomValues() - Web APIs | MDN
User agents are instead urged to provide the best entropy they can when generating random numbers, using a well-defined, efficient pseudorandom ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s possible to use the library in async mode by providing the
random
option item obtained in an async fashion:👋 Hi, stumbled across this issue today, read through the comments and wanted to mention that I think the case for using the async version of
randomBytes
is to avoid blocking the event loop because the operation may block waiting for entropy, which will almost never happen outside of a virtualized or containerized environment.But, it is not a hypothetical problem for workloads running in virtualized or containerized environments. A quick search for
random entropy block virtualized containerized
will turn up plenty of material on the subject.Personally, I’ve seen this problem manifest a few times in automated test suites that run in a containerized environment running on a virtualized environment - tests would time out waiting on
randomBytes
.Anyway, I haven’t noticed this issue with this library specifically (great library by the way!), and as was mentioned, it is possible to BYO random bytes, which can be procured asynchronously, so there doesn’t seem to be change required. I just wanted to try to add some context regarding why using the async version would be preferential for some use cases. ✌️