From 16616814115b88a373fe895c747bfa64d8c2a9a4 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 9 Jan 2025 11:46:48 -0500 Subject: [PATCH] fix: #13021, save details of follow request before sending the follow, avoid race condition --- src/api/activitypub.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/api/activitypub.js b/src/api/activitypub.js index 8400b60f98..20379025e3 100644 --- a/src/api/activitypub.js +++ b/src/api/activitypub.js @@ -46,13 +46,17 @@ activitypubApi.follow = enabledCheck(async (caller, { type, id, actor } = {}) => const handle = await user.getUserField(actor, 'username'); const timestamp = Date.now(); - await activitypub.send(type, id, [actor], { - id: `${nconf.get('url')}/${type}/${id}#activity/follow/${handle}/${timestamp}`, - type: 'Follow', - object: actor, - }); - await db.sortedSetAdd(`followRequests:${type}.${id}`, timestamp, actor); + try { + await activitypub.send(type, id, [actor], { + id: `${nconf.get('url')}/${type}/${id}#activity/follow/${handle}/${timestamp}`, + type: 'Follow', + object: actor, + }); + } catch (e) { + await db.sortedSetRemove(`followRequests:${type}.${id}`, actor); + throw e; + } }); // should be .undo.follow