[Bug]: After a streamed deep crawl is stopped early, the next deep crawl returns only the start page
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 12/100
Hướng nghiên cứu
Start at DeepCrawlDecorator, where the deep_crawl_active ContextVar is set to True, and at the finally in its stream wrapper that resets it. Run the reproduction script in the issue: a full crawl, a crawl stopped after two pages, then a third crawl that should return six pages but returns one. Done means the third crawl is no longer treated as nested. Pull request #2386 already targets this, so check it before starting.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
crawl4ai version
0.9.5 (same on 0.9.0)
Expected Behavior
Every crawler.arun(url, config) with a deep_crawl_strategy and stream=True runs a deep crawl, including after a previous streamed deep crawl was stopped early.
Current Behavior
If the caller stops iterating a streamed deep crawl (break), the next deep crawl from the same task returns only the start page.
DeepCrawlDecorator sets the deep_crawl_active ContextVar to True and resets it in the finally of the stream wrapper. When the caller leaves the stream without closing it, that finally runs later, when the generator is garbage-collected, in another context. The flag stays True in the caller's context, so the next arun() is treated as a nested call and falls through to a single-page crawl. The same happens if the stream is consumed from another task (for example asyncio.create_task(anext(stream))): the reset only reaches that task's copy of the context.
Is this reproducible?
Yes
Code snippets
import asyncio
from aiohttp import web
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig
from crawl4ai.deep_crawling import BFSDeepCrawlStrategy
PAGES = 5
async def handle(request):
links = "".join(f'<a href="/p{i}">p{i}</a>' for i in range(PAGES)) if request.path == "/" else ""
return web.Response(text=f"<html><body>{links}<p>{'text ' * 200}</p></body></html>", content_type="text/html")
async def deep_crawl(crawler, url, stop_after=None):
config = CrawlerRunConfig(deep_crawl_strategy=BFSDeepCrawlStrategy(max_depth=1), stream=True)
pages = []
async for result in await crawler.arun(url, config=config):
pages.append(result.url)
if stop_after and len(pages) == stop_after:
break # e.g. the caller restarts the crawl with another browser config
return pages
async def main():
app = web.Application()
app.router.add_get("/{tail:.*}", handle)
runner = web.AppRunner(app)
await runner.setup()
await web.TCPSite(runner, "127.0.0.1", 8765).start()
url = "http://127.0.0.1:8765/"
async with AsyncWebCrawler() as crawler:
print("full crawl:", len(await deep_crawl(crawler, url))) # 6
print("stopped early:", len(await deep_crawl(crawler, url, stop_after=2))) # 2
print("next crawl:", len(await deep_crawl(crawler, url))) # 1, expected 6
await runner.cleanup()
asyncio.run(main())
Suggested fix
Reset the flag as soon as deep_crawl_strategy.arun() has returned the stream, with the token from set(), instead of in the stream's finally. The strategies' own batches already run with deep_crawl_strategy=None, so the guard is not needed while the stream is consumed. Callers can work around it by closing the stream in their own task (async with contextlib.aclosing(stream)).
- Ngôn ngữ chính
- Python
- Star
- 85.9k
- Fork
- 8.9k
- Merge trung bình
- 5 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 24
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của unclecode/crawl4ai
-
[Bug]: Text after an inline <link>, <meta>, <style> or <noscript> is dropped from cleaned_html and markdownCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở🐞 Bug 🩺 Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
unclecode/crawl4ai#2416 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[Bug]: Since 0.9.1, Linux launches chrome-headless-shell instead of ChromiumCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở🐞 Bug 🩺 Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
unclecode/crawl4ai#2382 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[Bug]: BestFirstCrawlingStrategy fetches a full batch past max_pagesCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở🐞 Bug 🩺 Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
unclecode/crawl4ai#2381 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[Bug]: CrawlerRunConfig.clone() drops fallback_fetch_function, so deep crawls never use itCó thể đã có người làm @siva23367 đã nhận 2 ngày trước. Đang mở🐞 Bug 🩺 Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
unclecode/crawl4ai#2379 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[Bug]: Docker memory guard reads host RAM when no container limit is set — cgroup v2 "max" defeats get_container_memory_percentCó thể đã có người làm @Battleplus đã nhận 59 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
unclecode/crawl4ai#2123 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của unclecode/crawl4ai
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
volcengine/OpenViking#6445 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be editedCó thể đã có người làm @ManyaJain111 đã nhận hôm nay. Đang mởbug enhancement possible-duplicate
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
AOSSIE-Org/PictoPy#1637 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
deepspeedai/DeepSpeed#8884 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Flaky: test_advisor_live_calibrates_an_unmeasured_circuit ranks engines by a 1.8ms sleep marginĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
flagos-ai/FlagQuantum#718 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug CI-failure high priority
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
vllm-project/afd-plugin#483 ·
Maintainer thường phản hồi trong vòng 1 ngày