From 3077016f6112754585c05b7952e456be44b9d8cd Mon Sep 17 00:00:00 2001 From: John Fawcett Date: Mon, 9 Oct 2023 12:01:37 -0500 Subject: [PATCH] fix: Pages direct upload failing with expired JWT error (#2687) For projects which are slow to upload - either because of client bandwidth or large numbers of files and sizes - It's possible for the JWT to expire multiple times. Since our network request concurrency is set to 3, it's possible that each time the JWT expires we get 3 failed attempts. This can quickly exhaust our upload attempt count and cause the entire process to bail. This change makes it such that jwt refreshes do not count as a failed upload attempt. --- .changeset/dull-pans-happen.md | 9 +++++++++ packages/wrangler/src/pages/upload.tsx | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/dull-pans-happen.md diff --git a/.changeset/dull-pans-happen.md b/.changeset/dull-pans-happen.md new file mode 100644 index 000000000000..68beeed47ee5 --- /dev/null +++ b/.changeset/dull-pans-happen.md @@ -0,0 +1,9 @@ +--- +"wrangler": patch +--- + +Fixes large Pages projects failing to complete direct upload due to expiring JWTs + +For projects which are slow to upload - either because of client bandwidth or large numbers of files and sizes - It's possible for the JWT to expire multiple times. Since our network request concurrency is set to 3, it's possible that each time the JWT expires we get 3 failed attempts. This can quickly exhaust our upload attempt count and cause the entire process to bail. + +This change makes it such that jwt refreshes do not count as a failed upload attempt. diff --git a/packages/wrangler/src/pages/upload.tsx b/packages/wrangler/src/pages/upload.tsx index 821aa2056a30..e46597b9178c 100644 --- a/packages/wrangler/src/pages/upload.tsx +++ b/packages/wrangler/src/pages/upload.tsx @@ -228,7 +228,7 @@ export const upload = async ( logger.debug("failed:", e, "retrying..."); // Exponential backoff, 1 second first time, then 2 second, then 4 second etc. await new Promise((resolvePromise) => - setTimeout(resolvePromise, Math.pow(2, attempts++) * 1000) + setTimeout(resolvePromise, Math.pow(2, attempts) * 1000) ); if ( @@ -237,6 +237,9 @@ export const upload = async ( ) { // Looks like the JWT expired, fetch another one jwt = await fetchJwt(); + } else { + // Only count as a failed attempt if the error _wasn't_ an expired JWT + attempts++; } return doUpload(); } else {