Skip to content

Fix zip cleanup of pending source pulls - #144

Merged
vxgmichel merged 1 commit into
vxgmichel:mainfrom
Kuang-xianxin:fix/zip-pending-source-cleanup
Sep 14, 2026
Merged

vxgmichel merged 1 commit into
vxgmichel:mainfrom
Kuang-xianxin:fix/zip-pending-source-cleanup

Conversation

@Kuang-xianxin

Copy link
Copy Markdown
Contributor

When one source passed to stream.zip ends or raises while another source is still awaiting its next item, asyncio.gather returns without stopping that other pull. Its async generator remains running when the stream contexts exit, so its finally block is skipped and the pull can outlive the zip operation.

Manage each round of pulls with the existing TaskGroup. Pending pulls are cancelled and awaited before the source contexts close, while source order, strict length checks, and the original source exception are preserved.

The event-controlled regression covers shortest-source exhaustion and source errors in both strict and non-strict mode. It checks that the pending generator's cleanup has completed and its task has finished when zip exits; no timing sleeps are needed.

Validation:

  • All three new cases fail on the unmodified base (c098bec), then pass with the fix.
  • Full suite: 115 passed on both Python 3.9.25 and 3.13.14 (Windows).
  • Black, Flake8, and Ruff pass for the changed files using the repository's pinned versions.
  • Pinned Mypy and Pyright pass with the Linux platform target used by the quality job. Native Windows Mypy reports the same existing loop-policy assignment error in test_utils.py on both the base and the fixed tree.

@codecov

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c098bec) to head (0fc6c9b).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #144   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines         1172      1174    +2     
=========================================
+ Hits          1172      1174    +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vxgmichel

vxgmichel commented Sep 14, 2026 •

Copy link
Copy Markdown
Owner

Great catch! Thank you @Kuang-xianxin

It should be a general rule in the project that all the concurrency handling should go through aiostream.manager.TaskGroup, so great fix as well.

I also checked that the test properly detects the original issue, so perfect, I'm merging it as it is :)

@vxgmichel
vxgmichel merged commit a54225e into vxgmichel:main Sep 14, 2026
25 checks passed
@vxgmichel

Copy link
Copy Markdown
Owner

Released in v0.8.0 🎉

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.

2 participants