From 9fa34128750bd5c1b95f0f64a2021c01871f1fed Mon Sep 17 00:00:00 2001 From: Ricardo Date: Mon, 2 Mar 2026 11:40:43 +0100 Subject: [PATCH] fix: chain dropIndex before createIndex on ap_muted to prevent race condition The non-async init() fired dropIndex and createIndex concurrently, causing MongoDB to abort the index build (IndexBuildAborted error 276). Chain createIndex via .then() so it runs after the drop completes. Confab-Link: http://localhost:8080/sessions/e9d666ac-3c90-4298-9e92-9ac9d142bc06 --- index.js | 33 +++++++++++++++++++++------------ package.json | 2 +- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 559f65f..7f8fae5 100644 --- a/index.js +++ b/index.js @@ -1000,18 +1000,27 @@ export default class ActivityPubEndpoint { ); } - // Drop non-sparse indexes if they exist (created by earlier versions), - // then recreate with sparse:true so multiple null values are allowed. - this._collections.ap_muted.dropIndex("url_1").catch(() => {}); - this._collections.ap_muted.dropIndex("keyword_1").catch(() => {}); - this._collections.ap_muted.createIndex( - { url: 1 }, - { unique: true, sparse: true, background: true }, - ); - this._collections.ap_muted.createIndex( - { keyword: 1 }, - { unique: true, sparse: true, background: true }, - ); + // Muted collection — sparse unique indexes (allow multiple null values) + this._collections.ap_muted + .dropIndex("url_1") + .catch(() => {}) + .then(() => + this._collections.ap_muted.createIndex( + { url: 1 }, + { unique: true, sparse: true, background: true }, + ), + ) + .catch(() => {}); + this._collections.ap_muted + .dropIndex("keyword_1") + .catch(() => {}) + .then(() => + this._collections.ap_muted.createIndex( + { keyword: 1 }, + { unique: true, sparse: true, background: true }, + ), + ) + .catch(() => {}); this._collections.ap_blocked.createIndex( { url: 1 }, diff --git a/package.json b/package.json index f5c6739..3173d9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rmdes/indiekit-endpoint-activitypub", - "version": "2.4.0", + "version": "2.4.1", "description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.", "keywords": [ "indiekit",