[Bug]: Post-navigation page operations have no timeout, and page cleanup is skipped on task cancellation — pages can leak and crawls can hang forever
维护者通常 3 天内回复
评估
调研方向
Start in async_crawler_strategy.py at the post-navigation operations and the cleanup finally block, then inspect browser_adapter.py and browser_manager.py for timeout behavior. Reproduce the busy-page hang and cancellation path described in the issue. Done means post-navigation work is bounded by page_timeout and cancelled tasks still close their pages.
由索引模型根据 Issue 内容生成。
描述
Summary
Found while investigating #2202 (Docker containers accumulating renderer processes for weeks). Two related defects in async_crawler_strategy.py make it possible for a crawl to hang indefinitely and for its page to never be closed.
1. Nothing after navigation has a timeout
page_timeout only bounds page.goto() (async_crawler_strategy.py:762-764). Every page interaction after navigation is an un-timed call into the page's JS engine:
- overlay/consent removal —
remove_overlay_elements(:1550) - body-visibility check,
css_selectorextraction (:1102), image-dimension updates page.content()(:1115)- shadow-DOM flattening, iframe processing, user
js_code
The adapter is a plain pass-through to page.evaluate (browser_adapter.py:61-65), which has no timeout in Playwright. The repo never calls set_default_timeout except inside if self.config.accept_downloads: (browser_manager.py:1215-1217) — and default timeouts would not cover evaluate anyway. Only scan_full_page is wrapped in asyncio.wait_for.
A page whose main thread goes busy after DOMContentLoaded (bad loop, broken ad script, hostile page) therefore hangs the crawl forever, holding its page (= one renderer process) open. Verified with a page that starts a busy loop right after DCL: navigation succeeds, then arun() never returns, far past page_timeout.
2. The page-closing finally doesn't survive cancellation
The cleanup block (async_crawler_strategy.py:1216-1231) guards with except Exception. asyncio.CancelledError is a BaseException, so a task cancelled during the first await in that block (release_page_with_context) propagates out and page.close() is never reached — the page and its context refcount leak. Reachable from dispatcher/stream teardown paths that cancel in-flight tasks.
Impact
In long-lived processes (the Docker server's browser pool, any SDK user reusing a crawler), leaked pages accumulate indefinitely. Combined with the launch flags that disable background throttling, each leaked page also burns CPU forever. This is the core mechanism behind the multi-week renderer accumulation in #2202.
Proposed fix
- Wrap the post-navigation phase (or at minimum every
evaluate/content()call) inasyncio.wait_forwith a budget derived frompage_timeout, so a crawl always terminates. - Make the cleanup
finallycancellation-safe: catchBaseException(re-raisingCancelledErrorafter the page is closed) or shield the close.
- 主要语言
- Python
- 星标
- 85.9k
- 派生
- 8.9k
- 平均合并
- 5 天 6 小时
- 30 天内合并 PR
- 21
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
unclecode/crawl4ai 的其他 Issue
-
[Bug]: PathDepthScorer counts query and fragment slashes as path levels可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
[Bug]: Text after an inline <link>, <meta>, <style> or <noscript> is dropped from cleaned_html and markdown可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭🐞 Bug 🩺 Needs Triage
难度 2/5 1-3 小时 新手友好度 85/100
unclecode/crawl4ai#2416 · 1 条评论 ·
维护者通常 3 天内回复
-
[Bug]: Since 0.9.1, Linux launches chrome-headless-shell instead of Chromium可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭🐞 Bug 🩺 Needs Triage
难度 2/5 1-3 小时 新手友好度 72/100
unclecode/crawl4ai#2382 · 1 条评论 ·
维护者通常 3 天内回复
-
[Bug]: BestFirstCrawlingStrategy fetches a full batch past max_pages可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭🐞 Bug 🩺 Needs Triage
难度 2/5 1-3 小时 新手友好度 74/100
unclecode/crawl4ai#2381 · 1 条评论 ·
维护者通常 3 天内回复
-
[Bug]: CrawlerRunConfig.clone() drops fallback_fetch_function, so deep crawls never use it可能已有人在做 @siva23367 于 6 天前认领。 未关闭🐞 Bug 🩺 Needs Triage
难度 2/5 1-3 小时 新手友好度 78/100
unclecode/crawl4ai#2379 · 1 条评论 ·
维护者通常 3 天内回复
查看 unclecode/crawl4ai 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 84/100
GoogleCloudPlatform/gce-rescue#195 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
intake mcp-intake needs-ac needs-human-review priority:medium
难度 2/5 1-3 小时 新手友好度 67/100
Ikalus1988/MisakaNet#3848 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 75/100
521xueweihan/HelloGitHub#4105 ·
-
bug size:XS
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复