fix: 过滤链提前退出时清理异步过滤器 - #2305
Open
2gg-bit wants to merge 1 commit into
Open
fix: 过滤链提前退出时清理异步过滤器#23052gg-bit wants to merge 1 commit into
2gg-bit wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?
python -m pytest tests/unit/test_filter_chain_cleanup.py tests/deep_crawling/test_deep_crawl_resume.py -q --asyncio-mode=auto:41 passed。git diff --check通过。Checklist:
develop本 PR 由 OpenAI Codex 编写并执行所列本地验证,未声称经过人工审核。