-
-
Notifications
You must be signed in to change notification settings - Fork 914
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
Jest RANDOMBYTESREQUEST #566
Comments
Weird. I guess Jest is using That said, the Without a reproducible test case, I don't think this is actionable. If you want to reduce it down to a Minimal, Complete, and Verifiable example, I or one of the other contributors might be able to take a look, though. |
you can check on this repo: just do npm i and npm t |
Note the "Minimal" part of "Minimal, Complete, and Verifiable example". Your repo is installing 1,500+ modules 😕 . And, as I think was noted in that other issue, this is more an integration test than a unit test, so makes for a rather complex environment. Also, when I try running this on Repl.it, it runs out of memory. See https://replit.com/@broofa/nestj-jest-failing. So I'm not particularly inclined to investigate this further at this time. If you want us to pursue this, I suggest you par your test case down to something that can be reproduced on Repl.it. Ideally a single script that requires just ('uuid') and any node-internal modules that might be needed. Failing that, delete any/all code and dependencies that aren't absolutely necessary to reproduce the issue. Maybe look into what Jest is doing to track open handles, and use that to further reduce the overhead? |
I found myself this issue last week, and found some more info at https://stackoverflow.com/questions/65653226/jest-and-randombytesrequest-open-handles. Seems like an issue related with latests versions of Node.js. |
@jasnell I think you have made lots of significant contributions to Node.js crypto recently, do you have any pointers regarding the issue described above? |
Yeah there were recently some changes in this area that may be causing this. I'll investigate this morning. randomFillSync uses the same underlying mechanism as randomFill but invokes it synchronously. It's supposed to be marked weak so gc can clean it up immediately after but this error suggests that might not be happening so that's where I'll look first. |
FWIW I put together this test yesterday to see if randomFillSync() was triggering any async hooks, but didn't see anything because I was using node@14. (Failed to note @guiaramos was on node@15, dooh!) 'Tried it again on node@15 this morning after seeing @jasnell's comments and (surprise!) it shows an async task being generated.
[When your fellow contributors once again "just know"...] |
Ok, so I just confirmed that Here's the sample code I'm using to check: const { createHook } = require('async_hooks')
const { randomFillSync } = require('crypto');
const set = new Set();
const hook = createHook({
init(id, type) {
process._rawDebug(type);
if (type === 'RANDOMBYTESREQUEST') {
set.add(id);
process._rawDebug(`init ${id} ${type}`);
}
},
destroy(id) {
if (set.has(id)) {
process._rawDebug(`destroy ${id}`);
set.delete(id);
}
}
});
hook.enable();
const buf = new Uint8Array(10);
randomFillSync(buf);
gc(); Run this with the You should see:
To explain a bit about what's happening under the covers here: All of the |
I've created the above issue with the Jest project and am going to close this out, as it's pretty clear at this point that the issue lies outside our ( |
@jasnell As always, we appreciate your prompt and insightful help on this! |
Sorry for the large repo @broofa, and ty guys for the help! |
Any time, happy to help :-) |
Describe the bug
uuid is not allowing jest to exit:
the error is located on
uuid/src/rng.js
Line 8 in 91805f6
How to reproduce
on a Nestjs server just execute:
Expected behavior
exit jest without open handlers
Runtime
Additional information
https://stackoverflow.com/questions/66958699/jest-open-handle-randombytesrequest-on-nestjs-graphql
The text was updated successfully, but these errors were encountered: