Official Crawl4AI Cloud: a hosted web scraping, extraction, and search API for AI agents. Free API key, 1,000 credits a month, no card. Fully open source: this repo is the Apache-2.0 crawler that powers it, and you can self-host it.
Python aiai-agentscrawl4ai-cloudcrawlerdata-extractionllmmarkdownmcpopen-sourceplaywrightpythonragscraperweb-crawlerweb-crawlingweb-scraping
feat: add per-source timeout to DomainMapper
unclecode858c82714535
diff --git a/crawl4ai/async_configs.py b/crawl4ai/async_configs.pyindex 40deea8e..5938805f 100644--- a/crawl4ai/async_configs.py+++ b/crawl4ai/async_configs.py@@ -2237,6 +2237,7 @@ class DomainMapperConfig:probe_paths: Optional[List[str]] = None,common_subdomains: Optional[List[str]] = None,include_subdomains: bool = True,+ source_timeout: float = 30.0,use_browser_for_homepage: bool = False,verbose: Optional[bool] = None,cache_ttl_hours: int = 24,@@ -2263,6 +2264,9 @@ class DomainMapperConfig:include_subdomains: Discover and scan subdomains. When False, only scansthe exact domain provided (skips crt.sh, DNS guessing,Wayback/CC host discovery). Default True.+ source_timeout: Max seconds per discovery source. Sources that exceed+ this are killed and skipped. Prevents slow sources from+ blocking fast results. Default 30.0.use_browser_for_homepage: Use Playwright for JS-rendered homepages.verbose: Override logger verbose setting.cache_ttl_hours: Hours before cached results expire.@@ -2284,6 +2288,7 @@ class DomainMapperConfig:self.probe_paths = probe_pathsself.common_subdomains = common_subdomainsself.include_subdomains = include_subdomains+ self.source_timeout = source_timeoutself.use_browser_for_homepage = use_browser_for_homepageself.verbose = verboseself.cache_ttl_hours = cache_ttl_hoursdiff --git a/crawl4ai/domain_mapper.py b/crawl4ai/domain_mapper.pyindex d4ddf3c0..3c866abe 100644--- a/crawl4ai/domain_mapper.py+++ b/crawl4ai/domain_mapper.py@@ -332,13 +332,20 @@ class DomainMapper:prefixes.extend(config.common_subdomains)discovery_tasks.append(("dns", self._guess_subdomains(base_domain, prefixes, config)))- # Run all discovery in parallel+ # Run all discovery in parallel (per-source timeout)if discovery_tasks:- coros = [t[1] for t in discovery_tasks]+ source_timeout = getattr(config, "source_timeout", 30.0)+ coros = [+ asyncio.wait_for(t[1], timeout=source_timeout)+ for t in discovery_tasks+ ]names = [t[0] for t in discovery_tasks]results = await asyncio.gather(*coros, return_exceptions=True)for name, result in zip(names, results):- if isinstance(result, Exception):+ if isinstance(result, asyncio.TimeoutError):+ self._log("warning", "{source} discovery timed out after {timeout}s, skipping",+ params={"source": name, "timeout": source_timeout})+ elif isinstance(result, Exception):self._log("warning", "{source} discovery failed: {err}",params={"source": name, "err": str(result)})else:@@ -542,13 +549,21 @@ class DomainMapper:if "homepage" in sources:tasks["homepage"] = self._scan_homepage(host, base_domain, config)- # Run in parallel+ # Run in parallel (per-source timeout)if tasks:+ source_timeout = getattr(config, "source_timeout", 30.0)source_names = list(tasks.keys())- coros = list(tasks.values())+ coros = [+ asyncio.wait_for(c, timeout=source_timeout)+ for c in tasks.values()+ ]task_results = await asyncio.gather(*coros, return_exceptions=True)for name, result in zip(source_names, task_results):+ if isinstance(result, asyncio.TimeoutError):+ self._log("warning", "{source} scan timed out on {host} after {timeout}s, skipping",+ params={"source": name, "host": host, "timeout": source_timeout})+ continueif isinstance(result, Exception):self._log("warning", "{source} scan failed on {host}: {err}",params={"source": name, "host": host, "err": str(result)})