-
Notifications
You must be signed in to change notification settings - Fork 30k
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
worker: reset Isolate
stack limit after entering Locker
#31593
Conversation
It turns out that using `v8::Locker` undoes the effects of passing an explicit stack limit as part of the `Isolate`’s resource constraints. Therefore, reset the stack limit manually after entering a Locker. Refs: nodejs#26049 (comment)
The test added here failed on Win2012 R2 + VS2019 in CI. Not sure if it's fail-every-time or flaky, but either way, probably warrants investigation before landing.....
|
@Trott thanks for checking – I’ve updated the PR, leaving some wiggle room for inaccuracies. |
It turns out that using `v8::Locker` undoes the effects of passing an explicit stack limit as part of the `Isolate`’s resource constraints. Therefore, reset the stack limit manually after entering a Locker. Refs: #26049 (comment) PR-URL: #31593 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Landed in 9111e02 |
It turns out that using `v8::Locker` undoes the effects of passing an explicit stack limit as part of the `Isolate`’s resource constraints. Therefore, reset the stack limit manually after entering a Locker. Refs: #26049 (comment) PR-URL: #31593 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
It turns out that using `v8::Locker` undoes the effects of passing an explicit stack limit as part of the `Isolate`’s resource constraints. Therefore, reset the stack limit manually after entering a Locker. Refs: #26049 (comment) PR-URL: #31593 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
It turns out that using `v8::Locker` undoes the effects of passing an explicit stack limit as part of the `Isolate`’s resource constraints. Therefore, reset the stack limit manually after entering a Locker. Refs: #26049 (comment) PR-URL: #31593 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
It turns out that using `v8::Locker` undoes the effects of passing an explicit stack limit as part of the `Isolate`’s resource constraints. Therefore, reset the stack limit manually after entering a Locker. Refs: #26049 (comment) PR-URL: #31593 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
@addaleax Could you explain the effect of this change? Dos this mean |
@ulrichb Yes, that is correct. The stack size in Workers that V8 knows about is now the actual stack size that was used when creating the Workers. There is currently no way so set We’ve considered making the stack size configurable through the |
Thanks for your reply! Okay, I understand. Atm. this works for me because the hard-coded WT limit (4 MB?) is way larger than the default But to be future-proof, I'd really hope for a My use case: I'm hosting the TypeScript compiler in a WT (which is necessary because it is heavily CPU bound + non-async) and the TS compiler does a lot of recursion, which can possibly hit the stack limit dependent on user input :( Here is a synthetic example , which hits the recursion limit with N > ~2500 on my machine (TS v3.8.3): import fs from "fs";
import workerThreads from "worker_threads";
import ts from "typescript";
if (workerThreads.isMainThread) {
const worker = new workerThreads.Worker(__filename);
worker.on("exit", code => {
console.log(`Worker stopped with exit code ${code}`);
});
} else {
console.log("Hello from worker, TS version: " + ts.version);
fs.writeFileSync("TempLargeTSFile.ts", `
class MyBuilder { method(): this { return this; } }
export default new MyBuilder()
${[...Array(4000)].map(() => ` .method()`).join("\n")}
;
`);
const program = ts.createProgram(["TempLargeTSFile.ts"], { types: [] });
const emitResult = program.emit();
const diagnostics = [...ts.getPreEmitDiagnostics(program), ...emitResult.diagnostics];
console.log('diagnostics', diagnostics);
} |
@ulrichb So to be clear, you are using
I can just open a PR and we can see how that goes. |
Add `stackSizeMb` to the `resourceLimit` option group. Refs: nodejs#31593 (comment)
Yes.
Okay, so the actual stack limit is dependent on the OS process, and
Nice. Thank you! |
Yes, but only if you set it to a lower value than the actual stack size. 👍 |
Add `stackSizeMb` to the `resourceLimit` option group. Refs: #31593 (comment) PR-URL: #33085 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Add `stackSizeMb` to the `resourceLimit` option group. Refs: #31593 (comment) PR-URL: #33085 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Add `stackSizeMb` to the `resourceLimit` option group. Refs: #31593 (comment) PR-URL: #33085 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
It turns out that using
v8::Locker
undoes the effects ofpassing an explicit stack limit as part of the
Isolate
’sresource constraints.
Therefore, reset the stack limit manually after entering a Locker.
Refs: #26049 (comment)
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes