Skip to content

Clean up parallel SFTP requests on cancellation - #846

Merged
ronf merged 1 commit into
ronf:developfrom
omrzk:fix/cancel-parallel-sftp-845
Nov 14, 2026
Merged

ronf merged 1 commit into
ronf:developfrom
omrzk:fix/cancel-parallel-sftp-845

Conversation

@omrzk

@omrzk omrzk commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Cancelling a parallel SFTP file read or write leaves its outstanding requests running. Closing the SSH connection afterwards can produce unretrieved SFTPConnectionLost task exceptions.

Cancel and gather outstanding requests on every exit from the parallel I/O iterator. Keep completed tasks owned until their results are consumed, so closing the iterator between yielded blocks also retrieves the rest of the batch.

Fixes #845.

Validation: three new loopback cancellation regressions fail on current develop and pass with the fix; they cover read(), write(), and read_parallel() and reuse the same file and connection afterwards. The SFTP suite passes (599 tests, one skip; 377 subtests), and the full suite passes (1,764 tests, 51 skips; 4,249 subtests). All configured pre-commit checks pass on Python 3.12/Linux. Native macOS/Windows and optional unavailable cryptographic backends were not tested locally.

This contribution is provided under the project's EPL-2.0 / GPL-2.0-or-later license terms. Please list the contributor as omrzk.

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.87%. Comparing base (fab96ac) to head (afe3aef).
⚠️ Report is 265 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #846      +/-   ##
===========================================
+ Coverage    99.85%   99.87%   +0.02%     
===========================================
  Files           95      102       +7     
  Lines        27784    32750    +4966     
  Branches      2908     3141     +233     
===========================================
+ Hits         27743    32709    +4966     
  Misses          38       38              
  Partials         3        3              

☔ 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.

@ronf
ronf merged commit 7eab0b2 into ronf:develop Nov 14, 2026
20 checks passed
@ronf

ronf commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks very much for the PR! I'm going to add one additional change suggested by Claude to properly clean up the iterator if something inside the loop body raises an exception. Right now, this cleanup only occurs if the iter itself is cancelled.

@ronf

ronf commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Additional fix is now in commit f7056ae in "develop".

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.

Cancelling SFTPClientFile.read() leaves _SFTPParallelIO tasks with unretrieved exceptions

2 participants