Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions crawl4ai/async_webcrawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,13 +1107,18 @@ async def maybe_release_session():

if stream:
async def result_transformer():
inner = dispatcher.run_urls_stream(
crawler=self, urls=urls, config=config
)
try:
async for task_result in dispatcher.run_urls_stream(
crawler=self, urls=urls, config=config
):
async for task_result in inner:
yield transform_result(task_result)
finally:
# Auto-release session after streaming completes
# Ensure the inner dispatcher stream is fully closed
# before releasing the session — otherwise cleanup of
# active crawl tasks may overlap with session teardown.
# (See #2083: arun_many stream closure leaks tasks.)
await inner.aclose()
await maybe_release_session()

return result_transformer()
Expand Down