Skip to content

Commit

Permalink
Issue a purge request when we get a stale serial. (#57)
Browse files Browse the repository at this point in the history
* Issue a purge request when we get a stale serial.

* Fix formatting

* Add purge to exception method
  • Loading branch information
Xcelled authored and cooperlees committed Oct 18, 2018
1 parent 1287132 commit ca79f8f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/bandersnatch/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,22 @@ 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(
"Expected PyPI serial {} for request {} but got {}. "
+ "HTTP PURGE has been issued to the request url".format(
required_serial, path, got_serial
)
)
Expand Down

0 comments on commit ca79f8f

Please sign in to comment.