From 049bebc3e6150337e12b2fc727d2cec10ef1c498 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Tue, 1 Dec 2026 11:54:21 -0500 Subject: [PATCH] Give the feed fetch a deadline again The CodeRabbit fixes on the old redesign stack (ac95033) gave the feed request a 10s deadline, but it was lost when the build moved to fetching the feed once. A server that accepted the connection and never answered would hang the build. The feed now gets a 30s deadline over the whole request, body included, and the timeout names the feed. Co-Authored-By: Claude Opus 5.5 --- packages/starpod/src/lib/rss.ts | 30 ++++++++++++++++++++++++------ tests/unit/rss.test.ts | 12 ++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/starpod/src/lib/rss.ts b/packages/starpod/src/lib/rss.ts index dc8116e..d10ced5 100644 --- a/packages/starpod/src/lib/rss.ts +++ b/packages/starpod/src/lib/rss.ts @@ -42,14 +42,32 @@ function once, T>( }; } +// The deadline covers the whole request, body included, so a server that +// stalls fails the build instead of hanging it. Every page needs the feed, so +// it gets longer than the optional transcripts' 10s. +const FEED_TIMEOUT_MS = 30_000; + const fetchFeedXml = once(async (url: string) => { - const response = await fetch(url); - if (!response.ok) { - throw new Error( - `[starpod] Fetching the feed ${url} failed: ${response.status}` - ); + try { + const response = await fetch(url, { + signal: AbortSignal.timeout(FEED_TIMEOUT_MS) + }); + if (!response.ok) { + throw new Error( + `[starpod] Fetching the feed ${url} failed: ${response.status}` + ); + } + return await response.text(); + } catch (error) { + // An abort is a DOMException, which isn't an Error in every runtime. + if ((error as { name?: unknown } | null)?.name === 'TimeoutError') { + throw new Error( + `[starpod] Fetching the feed ${url} timed out after ${FEED_TIMEOUT_MS / 1000}s`, + { cause: error } + ); + } + throw error; } - return response.text(); }); // rss-to-json only takes a URL and fetches it with axios; an axios adapter diff --git a/tests/unit/rss.test.ts b/tests/unit/rss.test.ts index a39b94e..fc3ab30 100644 --- a/tests/unit/rss.test.ts +++ b/tests/unit/rss.test.ts @@ -80,4 +80,16 @@ describe('the feed', () => { await expect(getAllEpisodes(config)).resolves.toHaveLength(1); expect(fetchMock).toHaveBeenCalledTimes(2); }); + + it('is fetched with a deadline, and says so when it runs out', async () => { + fetchMock.mockImplementation(async (_url: string, init?: RequestInit) => { + expect(init?.signal).toBeInstanceOf(AbortSignal); + throw new DOMException('The operation timed out.', 'TimeoutError'); + }); + const { getAllEpisodes } = await loadRss(); + + await expect(getAllEpisodes(config)).rejects.toThrow( + 'Fetching the feed https://feed.example/podcast.xml timed out after 30s' + ); + }); });