diff --git a/CHANGES/5967.bugfix b/CHANGES/5967.bugfix new file mode 100644 index 0000000000..ebc7f81bc8 --- /dev/null +++ b/CHANGES/5967.bugfix @@ -0,0 +1,2 @@ +On the content-app, added ClientConnectionError (aiohttp) as an exception that can trigger +a retry when streaming content from a Remote. diff --git a/pulpcore/content/handler.py b/pulpcore/content/handler.py index 651af1bc5e..60c5aa2c4a 100644 --- a/pulpcore/content/handler.py +++ b/pulpcore/content/handler.py @@ -5,7 +5,7 @@ import re from gettext import gettext as _ -from aiohttp.client_exceptions import ClientResponseError +from aiohttp.client_exceptions import ClientResponseError, ClientConnectionError from aiohttp.web import FileResponse, StreamResponse, HTTPOk from aiohttp.web_exceptions import ( HTTPError, @@ -815,6 +815,13 @@ async def _stream_content_artifact(self, request, response, content_artifact): [pulpcore.plugin.models.ContentArtifact][] returned the binary data needed for the client. """ + # We should only retry with exceptions that happen before we receive any data + # and start streaming, as we can't rollback data if something happens after that. + RETRYABLE_EXCEPTIONS = ( + ClientResponseError, + UnsupportedDigestValidationError, + ClientConnectionError, + ) remote_artifacts = content_artifact.remoteartifact_set.select_related( "remote" @@ -823,8 +830,7 @@ async def _stream_content_artifact(self, request, response, content_artifact): try: response = await self._stream_remote_artifact(request, response, remote_artifact) return response - - except (ClientResponseError, UnsupportedDigestValidationError) as e: + except RETRYABLE_EXCEPTIONS as e: log.warning( "Could not download remote artifact at '{}': {}".format( remote_artifact.url, str(e)