Skip to content

Commit 23f37a8

Browse files
committed
fix(crawl): sane timeouts
1 parent 5fe95f1 commit 23f37a8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/crawl/src/crawl.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ async function loadSitemapWithoutRetries(sitemapUrl: string): Promise<string[]>
1818
if (!response.ok) {
1919
throw new Error(`Sitemap not found: ${response.status}`)
2020
}
21+
const controller = new AbortController()
22+
const timeoutId = setTimeout(() => controller.abort(), 10000) // 10 second timeout
23+
24+
try {
25+
const response = await fetch(sitemapUrl, {
26+
signal: controller.signal,
27+
headers: {
28+
'User-Agent': 'mdream-crawler/1.0',
29+
},
30+
})
31+
32+
clearTimeout(timeoutId)
33+
34+
if (!response.ok) {
35+
throw new Error(`Sitemap not found: ${response.status}`)
36+
}
2137

2238
const xmlContent = await response.text()
2339

0 commit comments

Comments
 (0)