mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-03 03:12:31 +00:00
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:
5 files changed
+17
-7
No files matched your search
@@ -449,6 +449,13 @@ class AccessControl {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async waitForReady() {
|
||||
if (this.hasLoaded) {
|
||||
return;
|
||||
}
|
||||
return this.refresh();
|
||||
}
|
||||
|
||||
whitelistMode() {
|
||||
return this.whitelistEnabled;
|
||||
}
|
||||
|
||||
@@ -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:",
|
||||
|
||||
@@ -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:",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user