repl,worker: fix crash when SharedArrayBuffer disabled#39718
repl,worker: fix crash when SharedArrayBuffer disabled#39718codebytere wants to merge 2 commits intonodejs:mainfrom
Conversation
BridgeAR
left a comment
There was a problem hiding this comment.
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
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).
|
Is it repl or worker (the subsystem)? |
|
@targos i guess sort of both? I can make it whatever you think would be preferable, but it'd be hit anytime anyone invoked |
Trott
left a comment
There was a problem hiding this comment.
LGTM with lint fix and either a test or a comment (or both).
@codebytere |
56f1396 to
51830bb
Compare
|
@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.
LGTM. Just left a comment how the test could be improved.
6e29e56 to
489fa03
Compare
489fa03 to
7c5a3e0
Compare
7c5a3e0 to
324adc2
Compare
|
There's a relevant failure in CI. The test added here fails when invoked with |
|
@Trott are you potentially able to replicate locally? i'm seeing passing when i run locally 🤔 |
324adc2 to
9ff558a
Compare
@codebytere That's not passing. The The lack of output, though, is odd.... |
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.
LGTM with my comments addressed.
| const { isMainThread, Worker } = require('worker_threads'); | ||
|
|
||
| // Regression test for https://github.com/nodejs/node/issues/39717. | ||
|
|
||
| const w = new Worker(__filename); | ||
|
|
||
| w.on('exit', common.mustCall((status) => { | ||
| assert.strictEqual(status, 2); | ||
| })); | ||
|
|
||
| if (!isMainThread) process.exit(2); |
There was a problem hiding this comment.
| const { isMainThread, Worker } = require('worker_threads'); | |
| // Regression test for https://github.com/nodejs/node/issues/39717. | |
| const w = new Worker(__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; | |
| const w = new Worker(__filename); | |
| w.on('exit', common.mustCall((status) => { | |
| assert.strictEqual(status, 2); | |
| })); | |
| } else { | |
| process.exit(2); | |
| } |
There was a problem hiding this comment.
@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 (typeof SharedArrayBuffer === 'undefined') return originalCwd(); |
There was a problem hiding this comment.
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().
| function main({ n }) { | ||
| if (typeof SharedArrayBuffer === 'undefined') { | ||
| throw new Error('SharedArrayBuffers must be enabled to run this benchmark'); | ||
| } |
There was a problem hiding this comment.
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.
|
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: