Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Pages direct upload failing with expired JWT error #2687

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -317,12 +317,15 @@ export const upload = async (
console.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 ((e as { code: number }).code === 8000013 || isJwtExpired(jwt)) {
// 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