Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.3k
repl,worker: fix crash when SharedArrayBuffer disabled#39718
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
BridgeAR left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will likely break process.cwd() after changing the directory as it will return a cached value.cwd() should also be protected in that case:
node/lib/internal/main/worker_thread.js
Lines 138 to 152 in 82b1b55
| // The counter is only passed to the workers created by the main thread, not | |
| // to workers created by other workers. | |
| letcachedCwd=''; | |
| letlastCounter=-1; | |
| constoriginalCwd=process.cwd; | |
| process.cwd=function(){ | |
| constcurrentCounter=Atomics.load(cwdCounter,0); | |
| if(currentCounter===lastCounter) | |
| returncachedCwd; | |
| lastCounter=currentCounter; | |
| cachedCwd=originalCwd(); | |
| returncachedCwd; | |
| }; | |
| workerIo.sharedCwdCounter=cwdCounter; |
I am fine doing that, I just wonder if this is a common situation at all. AFAIK we mostly do not check all possible configurations and do not officially support them?
If we want to support the flag, we should also add a test (while such test can't really protect from other potential SharedArrayBuffer usages).
codebytere commented Aug 9, 2021 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
targos commented Aug 9, 2021 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Is it repl or worker (the subsystem)? |
codebytere commented Aug 9, 2021
@targos i guess sort of both? I can make it whatever you think would be preferable, but it'd be hit anytime anyone invoked |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Trott left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with lint fix and either a test or a comment (or both).
targos commented Aug 10, 2021
@codebytere |
codebytere commented Aug 10, 2021
@BridgeAR i think that should do it - let me know if you had something else in mind tho! |
BridgeAR left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just left a comment how the test could be improved.
Uh oh!
There was an error while loading. Please reload this page.
6e29e56 to 489fa03Comparenodejs-github-bot commented Aug 10, 2021
Trott commented Aug 11, 2021
There's a relevant failure in CI. The test added here fails when invoked with |
codebytere commented Sep 2, 2021
@Trott are you potentially able to replicate locally? i'm seeing passing when i run locally 🤔 |
324adc2 to 9ff558aComparenodejs-github-bot commented Sep 2, 2021
Trott commented Sep 2, 2021 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@codebytere That's not passing. The The lack of output, though, is odd.... |
Trott commented Sep 2, 2021
The lack of output is legit. (Maybe we should update To replicate without the Python script, run this |
BridgeAR left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with my comments addressed.
| const{ isMainThread, Worker }=require('worker_threads'); | ||
| // Regression test for https://github.com/nodejs/node/issues/39717. | ||
| constw=newWorker(__filename); | ||
| w.on('exit',common.mustCall((status)=>{ | ||
| assert.strictEqual(status,2); | ||
| })); | ||
| if(!isMainThread)process.exit(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const{ isMainThread, Worker }=require('worker_threads'); | |
| // Regression test for https://github.com/nodejs/node/issues/39717. | |
| constw=newWorker(__filename); | |
| w.on('exit',common.mustCall((status)=>{ | |
| assert.strictEqual(status,2); | |
| })); | |
| if(!isMainThread)process.exit(2); | |
| const{ Worker }=require('worker_threads'); | |
| // Regression test for https://github.com/nodejs/node/issues/39717. | |
| // Do not use isMainThread so that this test itself can be run inside a Worker. | |
| if(!process.env.HAS_STARTED_WORKER){ | |
| process.env.HAS_STARTED_WORKER=1; | |
| constw=newWorker(__filename); | |
| w.on('exit',common.mustCall((status)=>{ | |
| assert.strictEqual(status,2); | |
| })); | |
| }else{ | |
| process.exit(2); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codebytere Are you ok if we commit this suggestion, run tests, check with @BridgeAR if they can then approve the PR,, and hopefully land? Or is there something about this suggestion that would make you reluctant to do that?
| process.cwd=function(){ | ||
| // SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer. | ||
| if(typeofSharedArrayBuffer==='undefined')returnoriginalCwd(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine but we could prevent replacing process.cwd in the first place, so that the extra check is not needed when calling process.cwd().
| functionmain({ n }){ | ||
| if(typeofSharedArrayBuffer==='undefined'){ | ||
| thrownewError('SharedArrayBuffers must be enabled to run this benchmark'); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main is going to be executed more than once. As such, it's probably best to move the check to the top of the file.
codebytere commented Sep 13, 2022
Closing as superseded by #41023 |
Closes#39717.
It's possible for SharedArrayBuffers to be disabled with
--no-harmony-sharedarraybufferso we first need to check that this isn't the case before attempting to use them in the repl or the following crash occurs: