⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
fix(worker): add per-feed timeout to RSS polling to prevent loop freeze
Marcin Rybak76e566c7861c
diff --git a/apps/worker/workers/rssPolling.ts b/apps/worker/workers/rssPolling.tsindex 1aca03c7..a5341a81 100644--- a/apps/worker/workers/rssPolling.ts+++ b/apps/worker/workers/rssPolling.ts@@ -8,6 +8,14 @@ import { safeFetch } from "@linkwarden/lib/safeFetch";const pollingIntervalInSeconds =(Number(process.env.NEXT_PUBLIC_RSS_POLLING_INTERVAL_MINUTES) || 60) * 60; // Default to one hour if not set+// Per-feed network timeout. safeFetch (node-fetch v2) has no default timeout,+// so a single feed whose server accepts the connection but never responds keeps+// its fetch pending forever. Because every feed is awaited together in one+// Promise.all below, that one hung request makes the whole batch never settle,+// which freezes the polling loop indefinitely (no further cycles ever run).+const feedTimeoutInMs =+ (Number(process.env.RSS_FEED_TIMEOUT_SECONDS) || 30) * 1000;+export async function startRSSPolling() {console.log("\x1b[34m%s\x1b[0m", "Starting RSS polling...");while (true) {@@ -15,13 +23,18 @@ export async function startRSSPolling() {const parser = new Parser();- await Promise.all(+ // allSettled (not all) so one failed feed can never reject the whole batch.+ await Promise.allSettled(rssSubscriptions.map(async (rssSubscription) => {+ const controller = new AbortController();+ const timeout = setTimeout(() => controller.abort(), feedTimeoutInMs);+try {await assertUrlIsSafeForServerSideFetch(rssSubscription.url);- const xml = await safeFetch(rssSubscription.url).then((res) =>- res.text()- );+ const xml = await safeFetch(rssSubscription.url, {+ signal: controller.signal,+ timeout: feedTimeoutInMs,+ }).then((res) => res.text());const feed = await parser.parseString(xml);await rssHandler(rssSubscription, feed);} catch (error) {@@ -30,6 +43,8 @@ export async function startRSSPolling() {`Error processing RSS feed ${rssSubscription.url}:`,error);+ } finally {+ clearTimeout(timeout);}}));