Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue a purge request when we get a stale serial. #57

Merged
merged 4 commits into from
Oct 18, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/bandersnatch/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ def get(self, path, required_serial, **kw):
required_serial, path, got_serial
)
)
# HACK: The following attempts to purge the cache of the page we
# just tried to fetch. This works around PyPI's caches sometimes
# returning a stale serial for a package. Ideally, this should
# be fixed on the PyPI side, at which point the following code
# should be removed.
logger.debug(f"Issuing a PURGE for {path} to clear the cache")
try:
self.session.request("PURGE", path, timeout=self.timeout)
except requests.exceptions.HTTPError:
logger.warning(
"Got an error when attempting to clear the cache", exc_info=True
)

raise StalePage(
"Expected PyPI serial {} for request {} but got {}".format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add to the exception message that we’ve sent a PURGE (more to remind me / other devs in the future)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but iirc the stalepage exception is just swallowed, so the message isn't seen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will if you have stop-on-error set in the config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

required_serial, path, got_serial
Expand Down