-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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_threads SharedArrayBuffer in multiple object properties cross-referenced randomly (object corruption?) #28559
Labels
Comments
eduardnegru
changed the title
SharedArrayBuffers are received in the wrong order inside workers.
Worker_threads SharedArrayBuffer in multiple object properties cross-referenced randomly (object corruption?)
Jul 5, 2019
I simplified this a bit. MasterThread.js const WorkerThread = require("worker_threads").Worker;
// Bug: the second object key (apples)
// always gets the wrong SharedArrayBuffer instances in the wrong keys.
const objFruits_A = {
oranges: {
x212: new SharedArrayBuffer(212),
x216: new SharedArrayBuffer(216),
x222: new SharedArrayBuffer(222)
},
apples: {
x100: new SharedArrayBuffer(100),
x104: new SharedArrayBuffer(104),
x108: new SharedArrayBuffer(108)
}
};
// Bug: the second object key (oranges)
// always gets the wrong SharedArrayBuffer instances in the wrong keys.
const objFruits_B = {
apples: {
x100: new SharedArrayBuffer(100),
x104: new SharedArrayBuffer(104),
x108: new SharedArrayBuffer(108)
},
oranges: {
x212: new SharedArrayBuffer(212),
x216: new SharedArrayBuffer(216),
x222: new SharedArrayBuffer(222)
}
};
const workerThread = new WorkerThread("./WorkerThread.js");
workerThread.postMessage(objFruits_A);
workerThread.postMessage(objFruits_B);
// The second key in the sent object seems to get the SharedArrayBuffer instances
// shuffled somehow for both objFruits_A and objFruits_B.
setTimeout(process.exit, 3000); WorkerThread.js: const parentPort = require("worker_threads").parentPort;
parentPort.on("message", console.log); Output:
|
addaleax
added
confirmed-bug
Issues with confirmed bugs.
worker
Issues and PRs related to Worker support.
labels
Jul 6, 2019
addaleax
added a commit
to addaleax/node
that referenced
this issue
Jul 6, 2019
V8 has a handle scope below each `GetSharedArrayBufferId()` call, so using a `v8::Local` that outlives that handle scope to store references to `SharedArrayBuffer`s is invalid and may cause accidental de-duplication of passed `SharedArrayBuffer`s. Use a persistent handle instead to address this issue. Fixes: nodejs#28559
3 tasks
@eduardnegru Thanks for opening an issue about this (and thanks @oxygen for the simplified reproduction), #28582 should address the bug :) |
targos
pushed a commit
that referenced
this issue
Jul 20, 2019
V8 has a handle scope below each `GetSharedArrayBufferId()` call, so using a `v8::Local` that outlives that handle scope to store references to `SharedArrayBuffer`s is invalid and may cause accidental de-duplication of passed `SharedArrayBuffer`s. Use a persistent handle instead to address this issue. Fixes: #28559 PR-URL: #28582 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
MainThread
WorkerThread
Output
The order of creating the keys in the object matters.
It appears there's some optimization in V8 which is disabled partially (object keys reordering).
When ordered this way, everything works fine:
I get the following output:
The text was updated successfully, but these errors were encountered: