diff --git a/CHANGES/7846.bugfix b/CHANGES/7846.bugfix new file mode 100644 index 0000000000..b71fc47ada --- /dev/null +++ b/CHANGES/7846.bugfix @@ -0,0 +1 @@ +Fix temp file leak in pull-through metadata streaming. diff --git a/pulpcore/content/handler.py b/pulpcore/content/handler.py index 671ab72c84..24f4f8f6e0 100644 --- a/pulpcore/content/handler.py +++ b/pulpcore/content/handler.py @@ -904,6 +904,7 @@ async def _match_and_stream(self, path, request): # Try to stream the RemoteArtifact and potentially save it as a new Content unit save_artifact = ( remote.get_remote_artifact_content_type(original_rel_path) is not None + and remote.policy != Remote.STREAMED ) ca = ContentArtifact(relative_path=original_rel_path) ra = RemoteArtifact(remote=remote, url=url, content_artifact=ca) @@ -1289,12 +1290,12 @@ async def handle_data(data): data_size_handled = data_size_handled + len(data) else: await response.write(data) - if remote.policy != Remote.STREAMED: + if save_artifact: await original_handle_data(data) async def finalize(): nonlocal failed_download - if save_artifact and remote.policy != Remote.STREAMED: + if save_artifact: await original_finalize() failed_download = False @@ -1342,7 +1343,7 @@ async def finalize(): if hasattr(downloader, "session"): await downloader.session.close() - if save_artifact and remote.policy != Remote.STREAMED: + if save_artifact: content_artifacts = await asyncio.shield( sync_to_async(self._save_artifact)(download_result, remote_artifact, request) )