mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Fix slow loading and NIP-07 decryption issues
- Reduced `fetchListIncrementally` timeout to 4000ms to fail faster on bad relays. - Added 15s timeout to decryption calls in `HashtagPreferencesService`, `UserBlockListManager`, and `SubscriptionsManager` to prevent infinite hangs. - Added handling for "message channel closed" error in `nip07Adapter` with a backoff delay to allow extension recovery. - Prioritized preserving cached data on decryption failure instead of resetting to empty state. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
8b9ef3858d
commit
dab94a5cfe
5 files changed
+45
-6
No files matched your search
@@ -19,7 +19,9 @@ async function retryNip07Call(operation, label) {
|
||||
throw error;
|
||||
}
|
||||
if (i < attempts - 1) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
const isChannelClosed = error?.message?.includes("message channel closed");
|
||||
const delay = isChannelClosed ? 250 : 100;
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -3643,7 +3643,7 @@ export class NostrClient {
|
||||
// Wrap fetch with a timeout to prevent hanging on slow relays
|
||||
let events = await withRequestTimeout(
|
||||
actualFetchFn(relayUrl, filter),
|
||||
6000,
|
||||
4000,
|
||||
null,
|
||||
`Fetch from ${relayUrl} timed out`
|
||||
);
|
||||
@@ -3678,7 +3678,7 @@ export class NostrClient {
|
||||
delete filter.since;
|
||||
const events = await withRequestTimeout(
|
||||
actualFetchFn(relayUrl, filter),
|
||||
6000,
|
||||
4000,
|
||||
null,
|
||||
`Full fetch fallback from ${relayUrl} timed out`
|
||||
);
|
||||
|
||||
@@ -588,7 +588,20 @@ class HashtagPreferencesService {
|
||||
return;
|
||||
}
|
||||
|
||||
const decryptResult = await this.decryptEvent(latest, normalized);
|
||||
let decryptResult;
|
||||
try {
|
||||
const decryptPromise = this.decryptEvent(latest, normalized);
|
||||
const timeoutPromise = new Promise((_, reject) =>
|
||||
setTimeout(
|
||||
() => reject(new Error("Decryption timed out after 15s")),
|
||||
15000,
|
||||
),
|
||||
);
|
||||
decryptResult = await Promise.race([decryptPromise, timeoutPromise]);
|
||||
} catch (error) {
|
||||
decryptResult = { ok: false, error };
|
||||
}
|
||||
|
||||
if (!decryptResult.ok) {
|
||||
userLogger.warn(
|
||||
`${LOG_PREFIX} Failed to decrypt hashtag preferences`,
|
||||
|
||||
+14
-1
@@ -467,7 +467,20 @@ class SubscriptionsManager {
|
||||
return;
|
||||
}
|
||||
|
||||
const decryptResult = await this.decryptSubscriptionEvent(newest, userPubkey);
|
||||
let decryptResult;
|
||||
try {
|
||||
const decryptPromise = this.decryptSubscriptionEvent(newest, userPubkey);
|
||||
const timeoutPromise = new Promise((_, reject) =>
|
||||
setTimeout(
|
||||
() => reject(new Error("Decryption timed out after 15s")),
|
||||
15000,
|
||||
),
|
||||
);
|
||||
decryptResult = await Promise.race([decryptPromise, timeoutPromise]);
|
||||
} catch (error) {
|
||||
decryptResult = { ok: false, error };
|
||||
}
|
||||
|
||||
if (!decryptResult.ok) {
|
||||
userLogger.error(
|
||||
"[SubscriptionsManager] Failed to decrypt subscription list:",
|
||||
|
||||
+12
-1
@@ -1011,10 +1011,21 @@ class UserBlockListManager {
|
||||
let decryptionError = null;
|
||||
|
||||
try {
|
||||
const [muteList, blockList] = await Promise.all([
|
||||
const decryptPromise = Promise.all([
|
||||
decryptEvent(newestMute),
|
||||
decryptEvent(newestBlock),
|
||||
]);
|
||||
const timeoutPromise = new Promise((_, reject) =>
|
||||
setTimeout(
|
||||
() => reject(new Error("Decryption timed out after 15s")),
|
||||
15000,
|
||||
),
|
||||
);
|
||||
|
||||
const [muteList, blockList] = await Promise.race([
|
||||
decryptPromise,
|
||||
timeoutPromise,
|
||||
]);
|
||||
|
||||
muteList.forEach((pk) => mergedPubkeys.add(pk));
|
||||
blockList.forEach((pk) => mergedPubkeys.add(pk));
|
||||
|
||||
Reference in new issue
Block a user