From 858c50695e9cf77e65a440ff39de995a43cbc2db Mon Sep 17 00:00:00 2001 From: Thomas Muldowney Date: Wed, 7 Feb 2024 15:10:12 -0600 Subject: [PATCH 1/4] Ensure cancel callbacks are cleaned up --- src/util/actor.js | 5 ++++- src/util/scheduler.js | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/util/actor.js b/src/util/actor.js index 12c066d931a..d83727f8f12 100644 --- a/src/util/actor.js +++ b/src/util/actor.js @@ -113,7 +113,8 @@ class Actor { // We're using a MessageChannel object to get throttle the process() flow to one at a time. const callback = this.callbacks[id]; const metadata = (callback && callback.metadata) || {type: "message"}; - this.cancelCallbacks[id] = this.scheduler.add(() => this.processTask(id, data), metadata); + const cancel = this.scheduler.add(() => this.processTask(id, data), metadata); + if (cancel) this.cancelCallbacks[id] = cancel; } else { // In the main thread, process messages immediately so that other work does not slip in // between getting partial data back from workers. @@ -123,6 +124,8 @@ class Actor { } processTask(id: number, task: any) { + // Always delete since we are no longer cancellable + delete this.cancelCallbacks[id]; if (task.type === '') { // The done() function in the counterpart has been called, and we are now // firing the callback in the originating actor, if there is one. diff --git a/src/util/scheduler.js b/src/util/scheduler.js index 1b603d59431..0f7112a936c 100644 --- a/src/util/scheduler.js +++ b/src/util/scheduler.js @@ -38,7 +38,7 @@ class Scheduler { this.nextId = 0; } - add(fn: TaskFunction, metadata: TaskMetadata): Cancelable { + add(fn: TaskFunction, metadata: TaskMetadata): Cancelable | null { const id = this.nextId++; const priority = getPriority(metadata); @@ -50,9 +50,8 @@ class Scheduler { } finally { if (m) PerformanceUtils.endMeasure(m); } - return { - cancel: () => {} - }; + // Don't return an empty cancel because we can't actually be cancelled + return null; } this.tasks[id] = {fn, metadata, priority, id}; From a5c2e4ecf662802e6b9c1bd311612da5a43520c4 Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Thu, 8 Feb 2024 12:04:32 +0200 Subject: [PATCH 2/4] Empty commit to trigger CI From 0a519c1c2c982eb3702536bb1b8f42079a4aa07c Mon Sep 17 00:00:00 2001 From: Thomas Muldowney Date: Thu, 8 Feb 2024 10:15:17 -0600 Subject: [PATCH 3/4] Remove duplicate delete call --- src/util/actor.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/actor.js b/src/util/actor.js index d83727f8f12..0f10ab51593 100644 --- a/src/util/actor.js +++ b/src/util/actor.js @@ -142,7 +142,6 @@ class Actor { } else { const buffers: Set = new Set(); const done = task.hasCallback ? (err: ?Error, data: mixed) => { - delete this.cancelCallbacks[id]; this.target.postMessage({ id, type: '', From af2f9468beb616f5f9797a9722e6566e202335dc Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Tue, 13 Feb 2024 12:36:32 +0200 Subject: [PATCH 4/4] Empty commit to trigger CI