Merge pull request #1550 from PR0M3TH3AN/fix-access-control-race-condition-14071267767979250687

Fix false "not whitelisted" errors by waiting for access control lists
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-01-22 23:41:01 -05:00
commit 28a01bd13f
5 files changed
+17 -7

No files matched your search

+7
View File
@@ -449,6 +449,13 @@ class AccessControl {
return Promise.resolve();
}
async waitForReady() {
if (this.hasLoaded) {
return;
}
return this.refresh();
}
whitelistMode() {
return this.whitelistEnabled;
}
+2 -2
View File
@@ -3776,7 +3776,7 @@ class Application {
try {
switch (action) {
case "ensure-ready":
await accessControl.ensureReady();
await accessControl.waitForReady();
context.ok = true;
break;
case "add-moderator":
@@ -8286,7 +8286,7 @@ class Application {
}
try {
await accessControl.ensureReady();
await accessControl.waitForReady();
} catch (error) {
devLogger.warn(
"Failed to ensure admin lists were loaded before playback:",
+2 -2
View File
@@ -1402,12 +1402,12 @@ export class NostrService {
}
async ensureAccessControlReady() {
if (!this.accessControl || typeof this.accessControl.ensureReady !== "function") {
if (!this.accessControl || typeof this.accessControl.waitForReady !== "function") {
return;
}
try {
await this.accessControl.ensureReady();
await this.accessControl.waitForReady();
} catch (error) {
userLogger.warn(
"[nostrService] Failed to ensure access control lists are ready:",
+3 -3
View File
@@ -64,7 +64,7 @@ async function waitForRelaysReady({ timeoutMs = TRUST_SEED_READY_TIMEOUT_MS } =
}
async function waitForAccessControl({ timeoutMs = TRUST_SEED_READY_TIMEOUT_MS } = {}) {
if (!accessControl || typeof accessControl.ensureReady !== "function") {
if (!accessControl || typeof accessControl.waitForReady !== "function") {
return { ok: true, timedOut: false };
}
@@ -72,12 +72,12 @@ async function waitForAccessControl({ timeoutMs = TRUST_SEED_READY_TIMEOUT_MS }
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => {
timedOut = true;
reject(new Error("accessControl ensureReady timed out"));
reject(new Error("accessControl ready check timed out"));
}, timeoutMs);
});
try {
await Promise.race([accessControl.ensureReady(), timeoutPromise]);
await Promise.race([accessControl.waitForReady(), timeoutPromise]);
return { ok: true, timedOut: false };
} catch (error) {
if (timedOut) {
+3
View File
@@ -158,6 +158,9 @@ test("bootstrap seeds track editor roster and ignore whitelist-only changes", as
ensureReady: async () => {
ensureReadyCalls += 1;
},
waitForReady: async () => {
ensureReadyCalls += 1;
},
getEditors: () => {
getEditorsCalls += 1;
return currentEditors;