From cc9bc7946641e8e7189e35d81eb70490e2b9f18f Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 23 Jul 2024 20:57:12 +0200 Subject: [PATCH] [backend] Set opts.removeOnComplete when discarding corrupt jobs (since the opts object is likely also corrupted) --- packages/backend/src/queue/processors/deliver.ts | 5 ++++- .../backend/src/queue/processors/ended-poll-notification.ts | 1 + packages/backend/src/queue/processors/inbox.ts | 5 ++++- packages/backend/src/queue/processors/noop.ts | 4 +++- packages/backend/src/queue/processors/webhook-deliver.ts | 5 ++++- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/queue/processors/deliver.ts b/packages/backend/src/queue/processors/deliver.ts index 946281c89..0e5b4ac79 100644 --- a/packages/backend/src/queue/processors/deliver.ts +++ b/packages/backend/src/queue/processors/deliver.ts @@ -20,7 +20,10 @@ const logger = new Logger("deliver"); let latest: string | null = null; export default async (job: Bull.Job) => { - if (job.data == null || Object.keys(job.data).length === 0) return "Skip (data was null or empty)"; + if (job.data == null || Object.keys(job.data).length === 0) { + job.opts.removeOnComplete = true; + return "Skip (data was null or empty)"; + } const { host } = new URL(job.data.to); const puny = toPuny(host); diff --git a/packages/backend/src/queue/processors/ended-poll-notification.ts b/packages/backend/src/queue/processors/ended-poll-notification.ts index cbdc67440..dafa11719 100644 --- a/packages/backend/src/queue/processors/ended-poll-notification.ts +++ b/packages/backend/src/queue/processors/ended-poll-notification.ts @@ -12,6 +12,7 @@ export async function endedPollNotification( done: any, ): Promise { if (job.data == null || Object.keys(job.data).length === 0) { + job.opts.removeOnComplete = true; done(); return; } diff --git a/packages/backend/src/queue/processors/inbox.ts b/packages/backend/src/queue/processors/inbox.ts index 2fe4bf653..5c52fb11d 100644 --- a/packages/backend/src/queue/processors/inbox.ts +++ b/packages/backend/src/queue/processors/inbox.ts @@ -28,7 +28,10 @@ const logger = new Logger("inbox"); // Processing when an activity arrives in the user's inbox export default async (job: Bull.Job): Promise => { - if (job.data == null || Object.keys(job.data).length === 0) return "Skip (data was null or empty)"; + if (job.data == null || Object.keys(job.data).length === 0) { + job.opts.removeOnComplete = true; + return "Skip (data was null or empty)"; + } const signature = job.data.signature; // HTTP-signature let activity = job.data.activity; diff --git a/packages/backend/src/queue/processors/noop.ts b/packages/backend/src/queue/processors/noop.ts index 5be01d1da..575a75209 100644 --- a/packages/backend/src/queue/processors/noop.ts +++ b/packages/backend/src/queue/processors/noop.ts @@ -2,4 +2,6 @@ import Bull from "bull"; // Processor to be registered for jobs with __default__ (unnamed) handlers in queues that only have named handlers // Prevents sporadic bogus jobs from clogging up the queues -export async function noop(_: Bull.Job): Promise { } +export async function noop(job: Bull.Job): Promise { + job.opts.removeOnComplete = true; +} diff --git a/packages/backend/src/queue/processors/webhook-deliver.ts b/packages/backend/src/queue/processors/webhook-deliver.ts index 84397033e..e821026dd 100644 --- a/packages/backend/src/queue/processors/webhook-deliver.ts +++ b/packages/backend/src/queue/processors/webhook-deliver.ts @@ -9,7 +9,10 @@ import config from "@/config/index.js"; const logger = new Logger("webhook"); export default async (job: Bull.Job) => { - if (job.data == null || Object.keys(job.data).length === 0) return "Skip (data was null or empty)"; + if (job.data == null || Object.keys(job.data).length === 0) { + job.opts.removeOnComplete = true; + return "Skip (data was null or empty)"; + } try { logger.debug(`delivering ${job.data.webhookId}`);