Skip to content

Commit d3c1916

Browse files
gerrod3ggainey
authored andcommitted
Fix not cleaning up on-demand temp files after failed download
fixes: #6975 (cherry picked from commit 0e52cd7) Made-with: Cursor
1 parent 20667f0 commit d3c1916

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

CHANGES/6975.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clean up on-demand temporary file left over on an aborted download.

pulpcore/content/handler.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,8 +1156,10 @@ async def handle_data(data):
11561156
await original_handle_data(data)
11571157

11581158
async def finalize():
1159+
nonlocal failed_download
11591160
if save_artifact and remote.policy != Remote.STREAMED:
11601161
await original_finalize()
1162+
failed_download = False
11611163

11621164
downloader = remote.get_downloader(
11631165
remote_artifact=remote_artifact,
@@ -1167,6 +1169,7 @@ async def finalize():
11671169
downloader.handle_data = handle_data
11681170
original_finalize = downloader.finalize
11691171
downloader.finalize = finalize
1172+
failed_download = True
11701173
try:
11711174
download_result = await downloader.run(
11721175
extra_data={"disable_retry_list": (DigestValidationError,)}
@@ -1193,6 +1196,13 @@ async def finalize():
11931196
"Learn more on <https://pulpproject.org/pulpcore/docs/user/learn/"
11941197
"on-demand-downloading/#on-demand-and-streamed-limitations>"
11951198
)
1199+
finally:
1200+
if failed_download:
1201+
if downloader.path:
1202+
await sync_to_async(os.unlink)(downloader.path)
1203+
1204+
if hasattr(downloader, "session"):
1205+
await downloader.session.close()
11961206

11971207
if content_length := response.headers.get("Content-Length"):
11981208
self._report_served_artifact_size(int(content_length))

0 commit comments

Comments
 (0)