From b73ee309e0a39d16bdf3e13ca80486d4a2b7e55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 28 Aug 2025 12:39:44 -0400 Subject: [PATCH] refactor: remove invalid queued items catch invalid json in payload --- src/activitypub/index.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/activitypub/index.js b/src/activitypub/index.js index eeb51c2887..df455ac89f 100644 --- a/src/activitypub/index.js +++ b/src/activitypub/index.js @@ -441,20 +441,34 @@ ActivityPub.send = async (type, id, targets, payload) => { async function retryFailedMessages() { const queueIds = await db.getSortedSetRangeByScore('ap:retry:queue', 0, 50, '-inf', Date.now()); - const queuedData = (await db.getObjects(queueIds.map(id => `ap:retry:queue:${id}`))).filter(Boolean); + const queuedData = (await db.getObjects(queueIds.map(id => `ap:retry:queue:${id}`))); const retryQueueAdd = []; const retryQueuedSet = []; const queueIdsToRemove = []; const oneMinute = 1000 * 60; - await Promise.all(queuedData.map(async (data) => { - const { queueId, uri, id, type, attempts, payload } = data; - const payloadObj = JSON.parse(payload); + await Promise.all(queuedData.map(async (data, index) => { + const queueId = queueIds[index]; + if (!data) { + queueIdsToRemove.push(queueId); + return; + } + const { uri, id, type, attempts, payload } = data; + if (!uri || !id || !type || !payload || attempts > 10) { + queueIdsToRemove.push(queueId); + return; + } + let payloadObj; + try { + payloadObj = JSON.parse(payload); + } catch (err) { + queueIdsToRemove.push(queueId); + return; + } const ok = await sendMessage(uri, id, type, payloadObj); - - if (ok || attempts > 10) { + if (ok) { queueIdsToRemove.push(queueId); } else { const nextAttempt = (parseInt(attempts, 10) || 0) + 1;