Skip to content

Commit 242e097

Browse files
committed
Ensure we correctly purge from the CDN and fail to publish the update if that fails
1 parent c6b9419 commit 242e097

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Package/V2Dumper.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,16 @@ private function writeV2File(Package $package, string $name, string $path, strin
421421
}
422422
} while ($retries-- > 0);
423423

424-
$this->cdnClient->purgeMetadataCache($relativePath);
424+
$retries = 3;
425+
do {
426+
if ($this->cdnClient->purgeMetadataCache($relativePath)) {
427+
break;
428+
}
429+
if ($retries === 0) {
430+
throw new \RuntimeException('Failed to purge cache for '.$relativePath);
431+
}
432+
sleep(1);
433+
} while ($retries-- > 0);
425434

426435
$this->redis->zadd('metadata-dumps', [$pkgWithDevFlag => $filemtime]);
427436
$this->statsd->increment('packagist.metadata_dump_v2');

src/Service/CdnClient.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function uploadMetadata(string $path, string $contents): int
4545
return $time;
4646
}
4747

48-
public function purgeMetadataCache(string $path): void
48+
public function purgeMetadataCache(string $path): bool
4949
{
5050
$resp = $this->httpClient->request('POST', 'https://api.bunny.net/purge?'.http_build_query(['url' => $this->metadataPublicEndpoint.$path, 'async' => 'true']), [
5151
'headers' => [
@@ -54,8 +54,12 @@ public function purgeMetadataCache(string $path): void
5454
]);
5555
// wait for status code at least
5656
if ($resp->getStatusCode() !== 200) {
57-
$this->logger->error('Failed purging '.$path.' from CDN');
57+
$this->logger->error('Failed purging '.$path.' from CDN', ['response' => $resp->getContent(false), 'status' => $resp->getStatusCode()]);
58+
59+
return false;
5860
}
61+
62+
return true;
5963
}
6064

6165
public function sendUploadMetadataRequest(string $path, string $contents): ResponseInterface

0 commit comments

Comments
 (0)