Skip to content

fix: await dispatcher cleanup in arun_many streams - #2136

Open
nightcityblade wants to merge 1 commit into
unclecode:developfrom
nightcityblade:fix/issue-2083-stream-cleanup
Open

fix: await dispatcher cleanup in arun_many streams#2136
nightcityblade wants to merge 1 commit into
unclecode:developfrom
nightcityblade:fix/issue-2083-stream-cleanup

Conversation

@nightcityblade

Copy link
Copy Markdown
Contributor

Summary

Fixes #2083.

Make the public AsyncWebCrawler.arun_many(..., stream=True) wrapper explicitly own and close the dispatcher stream. Closing the public stream now completes dispatcher cleanup before proxy-session release and before aclose() returns.

List of files changed and why

  • crawl4ai/async_webcrawler.py - close the inner dispatcher async generator with contextlib.aclosing().
  • tests/async/test_arun_many_stream_cleanup.py - verify that closing the public wrapper synchronously closes its dispatcher stream.

How Has This Been Tested?

  • .venv/bin/python -m pytest tests/async/test_arun_many_stream_cleanup.py tests/async/test_dispatchers.py::TestDispatchStrategies::test_memory_adaptive_stream_closure_cleans_up_tasks -q - 2 passed.
  • .venv/bin/ruff check --isolated --select E9,F63,F7,F82 --ignore F821 crawl4ai/async_webcrawler.py tests/async/test_arun_many_stream_cleanup.py - passed.
  • .venv/bin/black --check --target-version py312 --fast tests/async/test_arun_many_stream_cleanup.py - passed.
  • .venv/bin/python -m compileall -q crawl4ai/async_webcrawler.py tests/async/test_arun_many_stream_cleanup.py - passed.
  • git diff --check upstream/develop...HEAD - passed.

The full legacy tests/async/test_dispatchers.py module produced 10 passes and one unrelated pre-existing failure: test_monitor_integration still passes removed CrawlerMonitor(max_visible_rows=..., display_mode=...) arguments.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas - N/A; the ownership boundary is expressed directly with aclosing().
  • I have made corresponding changes to the documentation - N/A; this restores the documented async-generator cleanup contract.
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes - the relevant new and existing cleanup tests pass; one unrelated pre-existing test in the broader module fails as noted above.

@nightcityblade

nightcityblade commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

CI note: the only failing check is the repository's notify-discord job because DISCORD_WEBHOOK is empty for this fork PR. The job exits before any code validation; the focused local cleanup tests and lint checks reported in the PR body are green.

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