Skip to content

Commit

Permalink
fix: Pages direct upload failing with expired JWT error (#2687)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrf0110 authored Oct 9, 2023
1 parent f4d2891 commit 3077016
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .changeset/dull-pans-happen.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 4 additions & 1 deletion packages/wrangler/src/pages/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand Down

0 comments on commit 3077016

Please sign in to comment.