Bound extension job and window-alias state
Two service-worker leaks. Running jobs were only bounded by their watchdog, so a command flood could hold many timers and results for up to JOB_TIMEOUT_MS; cap concurrent jobs at 32 and reject beyond that, since a clear error beats an unresponsive worker. Window aliases were never removed, so storage kept an entry for every window the user had ever renamed. Prune aliases against the live window set on list, rename, and close rather than only on close, because windows also disappear without going through windows.close. Also extract the repeated job summary in perf.status into a helper.
This commit is contained in:
@@ -15,6 +15,11 @@ import type { Job, Serializable, ErrorLike, DispatchArgs } from '../types';
|
||||
// jobs only need to survive long enough for the CLI to poll their result.
|
||||
export const MAX_FINISHED_JOBS = 20;
|
||||
|
||||
// Cap simultaneously running background jobs. A hung job has a watchdog, but a
|
||||
// command flood could still pin many timers/results for up to JOB_TIMEOUT_MS.
|
||||
// Rejecting above this bound keeps service-worker memory predictable.
|
||||
export const MAX_RUNNING_JOBS = 32;
|
||||
|
||||
// Watchdog: if a runner never resolves/rejects (e.g. executeScript against a
|
||||
// dead tab), finalize the job as an error so its persist interval stops instead
|
||||
// of writing to api.storage.local every second forever.
|
||||
@@ -77,6 +82,11 @@ export class JobManager {
|
||||
}
|
||||
|
||||
async start(command: string, args: DispatchArgs, runner: JobRunner) {
|
||||
const runningCount = [...this.jobs.values()].filter(job => job.status === "running").length;
|
||||
if (runningCount >= MAX_RUNNING_JOBS) {
|
||||
throw new Error(`too many background jobs running (${runningCount}); wait for jobs to finish or cancel one`);
|
||||
}
|
||||
|
||||
const jobId = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
||||
const job: Job = {
|
||||
id: jobId,
|
||||
|
||||
Reference in New Issue
Block a user