Skip to content

Node.js based forum software built for the modern web

fix: #13021, save details of follow request before sending the follow, avoid race condition

Julian Lam16616814115b
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