Skip to content

Commit 6c276f1

Browse files
committed
Retry unavailable Worker version verification reads.
1 parent 7ef13f8 commit 6c276f1

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

‎packages/deploy-cloudflare/src/version.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,22 @@ async function activateCloudflareVersionWithSecretsFile(
13101310
}
13111311
options.onProgress?.('Verifying the uploaded Worker...');
13121312
if (inheritanceBaseline) {
1313-
const recent = await readRecentCloudflareVersionIds(options);
1313+
let recent = await readRecentCloudflareVersionIds(options);
1314+
// A failed read immediately after upload must not require another upload.
1315+
// Retry only unavailable metadata; unexpected version histories still fail.
1316+
for (let attempt = 0; recent === null && attempt < 2; attempt++) {
1317+
await (options.sleep ?? delay)(250 * 2 ** attempt);
1318+
if (!options.verifyUploader()) {
1319+
return {
1320+
ok: false,
1321+
reason: 'uploader-changed',
1322+
versionId,
1323+
previousVersionId: previous.versionId,
1324+
rollback: 'not-needed',
1325+
};
1326+
}
1327+
recent = await readRecentCloudflareVersionIds(options);
1328+
}
13141329
const previousLatest = inheritanceBaseline.at(-1);
13151330
const expected = [...inheritanceBaseline.map((version) => version.id), versionId].slice(-10);
13161331
if (recent === null) {

‎packages/deploy-cloudflare/test/unit/version.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,70 @@ describe('Cloudflare version activation', () => {
12341234
expect(commands.filter((command) => command === 'deployments status')).toHaveLength(4);
12351235
});
12361236

1237+
it.each(['recovers', 'unavailable', 'concurrent', 'uploader-changed'] as const)(
1238+
'bounds retries of an unavailable post-upload version list (%s)',
1239+
async (outcome) => {
1240+
const base = runner();
1241+
let uploaded = false;
1242+
let reads = 0;
1243+
let uploaderVerified = true;
1244+
const runWrangler = operationFixture((args: Array<string>) => {
1245+
if (args[0] === 'versions' && args[1] === 'upload') {
1246+
uploaded = true;
1247+
}
1248+
if (args[0] === 'versions' && args[1] === 'list' && uploaded) {
1249+
reads++;
1250+
if (reads === 1 || outcome === 'unavailable') {
1251+
return { status: 1, stdout: '', stderr: 'Version list temporarily unavailable' };
1252+
}
1253+
if (outcome === 'concurrent') {
1254+
return ok(
1255+
JSON.stringify([
1256+
{ id: CURRENT, number: 1 },
1257+
{ id: NEXT, number: 2 },
1258+
{ id: CONCURRENT, number: 3 },
1259+
]),
1260+
);
1261+
}
1262+
}
1263+
return base(args);
1264+
});
1265+
const sleep = vi.fn(async () => {
1266+
if (outcome === 'uploader-changed') {
1267+
uploaderVerified = false;
1268+
}
1269+
});
1270+
const result = await activateCloudflareVersion({
1271+
runWrangler,
1272+
workerName: 'my-worker',
1273+
verifyUploader: () => uploaderVerified,
1274+
verifyInheritedSecrets: true,
1275+
message: encodeCloudflareVersionMessage([], triggersWith()),
1276+
fetch: async () => Response.json({ ready: true }),
1277+
sleep,
1278+
});
1279+
expect(result).toMatchObject(
1280+
outcome === 'recovers'
1281+
? { ok: true, versionId: NEXT }
1282+
: {
1283+
ok: false,
1284+
reason:
1285+
outcome === 'unavailable'
1286+
? 'inheritance-source-unavailable'
1287+
: outcome === 'concurrent'
1288+
? 'inheritance-source-changed'
1289+
: 'uploader-changed',
1290+
},
1291+
);
1292+
expect(reads).toBe(outcome === 'unavailable' ? 3 : outcome === 'uploader-changed' ? 1 : 2);
1293+
expect(sleep.mock.calls).toEqual(outcome === 'unavailable' ? [[250], [500]] : [[250]]);
1294+
expect(runWrangler.mock.calls.filter(([args]) => args[1] === 'upload')).toHaveLength(1);
1295+
expect(runWrangler.mock.calls.some(([args]) => args[1] === 'deploy')).toBe(
1296+
outcome === 'recovers',
1297+
);
1298+
},
1299+
);
1300+
12371301
it('links an existing version without publishing routes or Worker settings', async () => {
12381302
const directory = mkdtempSync(join(tmpdir(), 'void-link-version-'));
12391303
const configPath = join(directory, 'wrangler.json');

0 commit comments

Comments
 (0)