Skip to content

Commit

Permalink
fixup: make disable-time configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-psb committed Nov 28, 2024
1 parent c66bc70 commit 03d1a11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pulpcore/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@
"EXPIRES_TTL": 600, # 10 minutes
}

# The time a RemoteArtifact will be ignored after failure.
# In on-demand, if a fetching content from a remote failed due to corrupt data,
# the corresponding RemoteArtifact will be ignored for that time (seconds).
FAILED_REMOTE_ARTIFACT_PROTECTION_TIME = 5 * 60 # 5 minutes

SPECTACULAR_SETTINGS = {
"SERVE_URLCONF": ROOT_URLCONF,
"DEFAULT_GENERATOR_CLASS": "pulpcore.openapi.PulpSchemaGenerator",
Expand Down
12 changes: 7 additions & 5 deletions pulpcore/content/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,24 +822,25 @@ 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
# We should only skip exceptions that happen before we receive any data
# and start streaming, as we can't rollback data if something happens after that.
RETRYABLE_EXCEPTIONS = (
SKIPPABLE_EXCEPTIONS = (
ClientResponseError,
UnsupportedDigestValidationError,
ClientConnectionError,
)

protection_time = settings.FAILED_REMOTE_ARTIFACT_PROTECTION_TIME
remote_artifacts = (
content_artifact.remoteartifact_set.select_related("remote")
.order_by_acs()
.exclude(failed_at__gte=timezone.now() - timedelta(minutes=5))
.exclude(failed_at__gte=timezone.now() - timedelta(seconds=protection_time))
)
async for remote_artifact in remote_artifacts:
try:
response = await self._stream_remote_artifact(request, response, remote_artifact)
return response
except RETRYABLE_EXCEPTIONS as e:
except SKIPPABLE_EXCEPTIONS as e:
log.warning(
"Could not download remote artifact at '{}': {}".format(
remote_artifact.url, str(e)
Expand Down Expand Up @@ -1148,12 +1149,13 @@ async def finalize():
await remote_artifact.asave()
await downloader.session.close()
close_tcp_connection(request.transport._sock)
FAILED_REMOTE_ARTIFACT_PROTECTION_TIME = settings.FAILED_REMOTE_ARTIFACT_PROTECTION_TIME
raise RuntimeError(
f"Pulp tried streaming {remote_artifact.url!r} to "
"the client, but it failed checksum validation.\n\n"
"We can't recover from wrong data already sent so we are:\n"
"- Forcing the connection to close.\n"
"- Marking this Remote Server to be ignored for 5 minutes.\n\n"
f"- Marking this Remote to be ignored for {FAILED_REMOTE_ARTIFACT_PROTECTION_TIME=}s.\n\n"
"If the Remote is known to be fixed, try resyncing the associated repository.\n"
"If the Remote is known to be permanently corrupted, try removing "
"affected Pulp Remote, adding a good one and resyncing.\n"
Expand Down

0 comments on commit 03d1a11

Please sign in to comment.