1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-24 20:19:10 +02:00

Chore: Sync fuzzer: Fix "DecryptionWorker: Cannot start because..." warning (#12925)

This commit is contained in:
Henry Heino
2025-08-18 06:04:26 -07:00
committed by GitHub
parent 06b681d897
commit 34b7f4e1f8

View File

@@ -8,6 +8,7 @@ import shim from '../shim';
import KvStore from './KvStore';
import EncryptionService from './e2ee/EncryptionService';
import PerformanceLogger from '../PerformanceLogger';
import AsyncActionQueue from '../AsyncActionQueue';
const EventEmitter = require('events');
const perfLogger = PerformanceLogger.create();
@@ -44,7 +45,7 @@ export default class DecryptionWorker {
private eventEmitter_: any;
private kvStore_: KvStore = null;
private maxDecryptionAttempts_ = 2;
private startCalls_: boolean[] = [];
private taskQueue_: AsyncActionQueue = new AsyncActionQueue();
private encryptionService_: EncryptionService = null;
public constructor() {
@@ -328,15 +329,25 @@ export default class DecryptionWorker {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
public async start(options: any = {}) {
this.startCalls_.push(true);
const startTask = perfLogger.taskStart('DecryptionWorker/start');
public async start(options: any = {}): Promise<DecryptionResult> {
let output = null;
try {
output = await this.start_(options);
} finally {
this.startCalls_.pop();
startTask.onEnd();
let lastError: Error;
// Use taskQueue_ to ensure that only one decryption task is running at a time.
this.taskQueue_.push(async () => {
const startTask = perfLogger.taskStart('DecryptionWorker/start');
try {
output = await this.start_(options);
} catch (error) {
lastError = error;
} finally {
startTask.onEnd();
}
});
await this.taskQueue_.processAllNow();
if (lastError) {
throw lastError;
}
return output;
}
@@ -350,13 +361,6 @@ export default class DecryptionWorker {
this.eventEmitter_ = null;
DecryptionWorker.instance_ = null;
return new Promise((resolve) => {
const iid = shim.setInterval(() => {
if (!this.startCalls_.length) {
shim.clearInterval(iid);
resolve(null);
}
}, 100);
});
await this.taskQueue_.waitForAllDone();
}
}