Merge pull request #1854 from PR0M3TH3AN/codex/update-fetchlistincrementally-timeout-parameter

Add configurable timeout for incremental Nostr list fetches
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-01-27 16:51:28 -05:00
commit 5cac280c3d
4 files changed
+11 -2

No files matched your search

+7 -2
View File
@@ -3549,6 +3549,7 @@ export class NostrClient {
* @param {string} [params.dTag] - Optional d-tag for addressable events (NIP-33).
* @param {string[]} [params.relayUrls] - List of relays to query. Defaults to client's configured relays.
* @param {function} [params.fetchFn] - Custom fetch function (mocks or specialized logic). Defaults to `pool.list`.
* @param {number} [params.timeoutMs] - Optional per-relay timeout for list fetches; defaults to a higher list-friendly baseline.
* @returns {Promise<import("nostr-tools").Event[]>} Deduplicated list of events found across all relays.
*/
async fetchListIncrementally({
@@ -3558,6 +3559,7 @@ export class NostrClient {
relayUrls,
fetchFn,
since,
timeoutMs = 10000,
} = {}) {
// Explanation:
// Optimizes network usage by only fetching "new" events from each relay.
@@ -3639,11 +3641,14 @@ export class NostrClient {
doFullFetch = false;
}
// Allow callers to override list fetch timeouts without changing non-list query behavior.
const listTimeoutMs = Number.isFinite(timeoutMs) && timeoutMs > 0 ? timeoutMs : 10000;
try {
// Wrap fetch with a timeout to prevent hanging on slow relays
let events = await withRequestTimeout(
actualFetchFn(relayUrl, filter),
4000,
listTimeoutMs,
null,
`Fetch from ${relayUrl} timed out`
);
@@ -3678,7 +3683,7 @@ export class NostrClient {
delete filter.since;
const events = await withRequestTimeout(
actualFetchFn(relayUrl, filter),
4000,
listTimeoutMs,
null,
`Full fetch fallback from ${relayUrl} timed out`
);
+1
View File
@@ -517,6 +517,7 @@ class HashtagPreferencesService {
dTag: HASHTAG_IDENTIFIER,
relayUrls: relays,
since,
timeoutMs: 12000,
}),
);
+1
View File
@@ -451,6 +451,7 @@ class SubscriptionsManager {
dTag: SUBSCRIPTION_LIST_IDENTIFIER,
relayUrls,
since: shouldForceFullFetch ? 0 : undefined,
timeoutMs: 12000,
});
// Also check session actor if different?
+2
View File
@@ -1115,6 +1115,7 @@ class UserBlockListManager {
pubkey: normalized,
relayUrls: relays,
since: fetchSince,
timeoutMs: 12000,
}),
nostrClient.fetchListIncrementally({
kind: 30002,
@@ -1122,6 +1123,7 @@ class UserBlockListManager {
dTag: BLOCK_LIST_IDENTIFIER,
relayUrls: relays,
since: fetchSince,
timeoutMs: 12000,
}),
]);