Skip to content

fix: 过滤链提前退出时清理异步过滤器 - #2305

Open
2gg-bit wants to merge 1 commit into
unclecode:developfrom
2gg-bit:codex/fix-filter-chain-awaitable-cleanup
Open

2gg-bit wants to merge 1 commit into
unclecode:developfrom
2gg-bit:codex/fix-filter-chain-awaitable-cleanup

Conversation

@2gg-bit

@2gg-bit 2gg-bit commented Sep 27, 2026

Copy link
Copy Markdown

Summary

修复 FilterChain.apply() 提前退出时遗留异步过滤器的问题:异步过滤器先返回 coroutine/Task/Future,后面的同步过滤器拒绝 URL 或抛出异常时,原实现直接退出,造成未等待的 coroutine 警告或后台任务泄漏。另外,gather 中一个过滤器报错时,其他过滤器仍可能继续运行。

List of files changed and why

  • crawl4ai/deep_crawling/filters.py:将已接收的 awaitable 纳入 Future 管理,在 finally 中取消尚未完成的过滤器并等待清理。保留同步拒绝的短路行为、并发执行、原始异常及正常返回结果。
  • tests/unit/test_filter_chain_cleanup.py:覆盖 coroutine、Task、Future × 同步拒绝/异常,以及异步失败后的兄弟任务清理和正常布尔结果。

How Has This Been Tested?

  • 原实现:7 failed, 2 passed。
  • python -m pytest tests/unit/test_filter_chain_cleanup.py tests/deep_crawling/test_deep_crawl_resume.py -q --asyncio-mode=auto:41 passed。
  • 新增测试使用 Black 格式化,git diff --check 通过。
  • Windows / Python 3.12.13;使用内存中的事件和 awaitable,无浏览器或网络请求。完整集成测试未运行。

Checklist:

  • 基于并提交到 develop
  • 保持所在代码的风格,自查差异
  • 新增回归测试,所列相关测试通过
  • 完整浏览器集成测试(未运行)

本 PR 由 OpenAI Codex 编写并执行所列本地验证,未声称经过人工审核。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant