Fix residual leak in downloadDirectory by skipping file downloads after cancellation.#6983
Open
RanVaknin wants to merge 2 commits into
Open
Fix residual leak in downloadDirectory by skipping file downloads after cancellation.#6983RanVaknin wants to merge 2 commits into
downloadDirectory by skipping file downloads after cancellation.#6983RanVaknin wants to merge 2 commits into
Conversation
added 2 commits
May 19, 2026 21:04
… cancelled to prevent directory recreation
downloadDirectory by skipping file downloads after cancellation.
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.
In #6875, we addressed canceling in flight transfers when a directory download is cancelled. That fix reduced the leaked
files per orphaned directory from thousands to single digits in stress test. However there was a residual leak for downloads that were already dispatched to
doDownloadSingleFile(the method that creates the destination directory and initiates the file download) before the cancellation signal propagated.When cancellation occurs, thread A calls
subscription.cancel()to stop new items from being delivered. Meanwhile, thread B has already picked up an item fromonNextand is insidedoDownloadSingleFile. Since it entered before thread A's cancellation took effect, it creates the destination directory and starts a download into it.This PR adds a
isDone()guard at the top ofdoDownloadSingleFileso that any thread that entered the method beforecancellation took effect will return early before touching the filesystem.
The two tests:
Updated
downloadDirectory_cancel_shouldCancelAllFutures- now waits for both downloads to start before cancelling. The original test calledcancel()immediately afterdownloadDirectory(), implicitly assuming all downloads would always start regardless of cancellation state. With the newisDone()guard, that assumption is not always true since cancel can now prevent downloads from starting. The test's intent is unchanged (in flight futures get cancelled), we just ensure bothfutures are actually in flight before cancelling. (Sanity check tested this with a repeated test suite 1000 times to make sure its deterministic)
Added
downloadDirectory_cancelledFuture_shouldNotCreateDirectories- The test cancels the directory download future, then delivers an S3 object through the publisher. Asserts that the destination subdirectory was never created on the filesystem. Without the fix,doDownloadSingleFilewould callcreateParentDirectoriesIfNeeded()and create the directory despite the cancellation.