Repository: pulp/pulpcore

Issue:
Raise 404 instead of 502 when expected file is missing from the FS.
After content sync/upload remove the artifact from /var/lib/pulp/media/artifact/...
```
$ http https://pulp3-source-fedora34.fluffy.example.com/pulp/content/test_path/1.iso
HTTP/1.1 502 Bad Gateway
Connection: keep-alive
Content-Length: 157
Content-Type: text/html
Date: Tue, 01 Feb 2022 14:17:11 GMT
Server: nginx/1.20.1

<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.20.1</center>
</body>
</html>


(pulp) [vagrant@pulp3-source-fedora34 ~]$ sudo journalctl -r
-- Journal begins at Fri 2022-01-07 03:33:20 UTC, ends at Tue 2022-02-01 14:17:30 UTC. --

Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]: FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/pulp/media/artif>
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:     return self._accessor.stat(self)
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:   File "/usr/lib64/python3.9/pathlib.py", line 1232, in stat
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:     result = self.fn(*self.args, **self.kwargs)
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:   File "/usr/lib64/python3.9/concurrent/futures/thread.py", line 52, in run
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:     st: os.stat_result = await loop.run_in_executor(None, filepath.stat)
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:   File "/usr/local/lib/pulp/lib64/python3.9/site-packages/aiohttp/web_fileresponse>
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:     await prepare_meth(request)
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:   File "/usr/local/lib/pulp/lib64/python3.9/site-packages/aiohttp/web_protocol.py">
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:     reset = await self.finish_response(request, resp, start_time)
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:   File "/usr/local/lib/pulp/lib64/python3.9/site-packages/aiohttp/web_protocol.py">
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:     resp, reset = await task
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]:   File "/usr/local/lib/pulp/lib64/python3.9/site-packages/aiohttp/web_protocol.py">
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]: Traceback (most recent call last):
Feb 01 14:17:11 pulp3-source-fedora34.fluffy.example.com gunicorn[154878]: [2022-02-01 14:17:11 +0000] [154878] [ERROR] Unhandled exception
```


Discussion:

Resolving patch:
diff --git a/pulpcore/content/handler.py b/pulpcore/content/handler.py
--- a/pulpcore/content/handler.py
+++ b/pulpcore/content/handler.py
@@ -772,7 +772,10 @@ async def _serve_content_artifact(self, content_artifact, headers, request):
         artifact_name = artifact_file.name
 
         if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem":
-            return FileResponse(os.path.join(settings.MEDIA_ROOT, artifact_name), headers=headers)
+            path = os.path.join(settings.MEDIA_ROOT, artifact_name)
+            if not os.path.exists(path):
+                raise Exception(_("Expected path '{}' is not found").format(path))
+            return FileResponse(path, headers=headers)
         elif settings.DEFAULT_FILE_STORAGE == "storages.backends.s3boto3.S3Boto3Storage":
             content_disposition = f"attachment;filename={content_artifact.relative_path}"
             parameters = {"ResponseContentDisposition": content_disposition}


Test patch: