Skip to content
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

queso backport: Use randomly generated task IDs to avoid collisions when receiving messages from multiple workers #8710

Merged
merged 1 commit into from
Aug 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/util/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class Actor {
cancelCallbacks: { number: Cancelable };
invoker: ThrottledInvoker;

static taskId: number;

constructor(target: any, parent: any, mapId: ?number) {
this.target = target;
this.parent = parent;
Expand All @@ -53,7 +51,11 @@ class Actor {
* @private
*/
send(type: string, data: mixed, callback: ?Function, targetMapId: ?string): ?Cancelable {
const id = ++Actor.taskId;
// We're using a string ID instead of numbers because they are being used as object keys
// anyway, and thus stringified implicitly. We use random IDs because an actor may receive
// message from multiple other actors which could run in different execution context. A
// linearly increasing ID could produce collisions.
const id = Math.round((Math.random() * 1e18)).toString(36).substring(0, 10);
if (callback) {
this.callbacks[id] = callback;
}
Expand Down Expand Up @@ -192,6 +194,4 @@ class Actor {
}
}

Actor.taskId = 0;

export default Actor;