cloudflare / workers-sdk

ā›…ļø Home to Wrangler, the CLI for Cloudflare WorkersĀ®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.71k stars 710 forks source link

šŸ› BUG: slow internet connection causes crashes #4919

Open jlarmstrongiv opened 9 months ago

jlarmstrongiv commented 9 months ago

Which Cloudflare product(s) does this pertain to?

Pages

What version(s) of the tool(s) are you using?

wrangler 3.26.0

What version of Node are you using?

v20.11.0

What operating system and version are you using?

Mac Sonoma 14.3

Describe the Bug

Observed behavior

/Users/user/Desktop/projects/project/node_modules/wrangler/wrangler-dist/cli.js:29572
            throw a;
            ^

FatalError: Failed to upload files. Please try again. Error: {"text":"Received a malformed response from the API","notes":[{"text":"Expired JWT"},{"text":"POST /pages/assets/upload -> 403 Forbidden"}],"kind":"error","name":"APIError"})
    at /Users/user/Desktop/projects/project/node_modules/wrangler/wrangler-dist/cli.js:147236:13
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async run (/Users/users/Desktop/projects/project/node_modules/wrangler/wrangler-dist/cli.js:146760:26) {
  code: 1
}

In essence, because of my slow internet and just a few large uploads, I am never able to publish my website to Cloudflare pages.

Expected behavior

Uploads all files successfully. Allow for resuming uploads or refreshing the JWT or increasing the JWT timeout.

Steps to reproduce

  1. Have a slow internet connect.
  2. Have a plain static site with say 10 large images that are 20mb each.
  3. Run npx wrangler pages deploy dist

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

/Users/user/Desktop/projects/project/node_modules/wrangler/wrangler-dist/cli.js:29572
            throw a;
            ^

FatalError: Failed to upload files. Please try again. Error: {"text":"Received a malformed response from the API","notes":[{"text":"Expired JWT"},{"text":"POST /pages/assets/upload -> 403 Forbidden"}],"kind":"error","name":"APIError"})
    at /Users/user/Desktop/projects/project/node_modules/wrangler/wrangler-dist/cli.js:147236:13
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async run (/Users/users/Desktop/projects/project/node_modules/wrangler/wrangler-dist/cli.js:146760:26) {
  code: 1
}
petebacondarwin commented 9 months ago

It looks like your upload JWT is expiring during the upload process. I need to look up what the expiry time on that token is but I can't imagine it is that small.

Do any assets get uploaded? You mention 10 x 20Mb files. If, say, the first 3 get uploaded before it crashes, then the next time you try a deployment it should skip those, which means that you would get to full deployment eventually. (I am not saying this is acceptable DX but it is a workaround).

I think we probably just need to make Wrangler more resilient to the upload token expiring, renew it more automatically, and try again, without bothering the user.

jlarmstrongiv commented 9 months ago

Do any assets get uploaded?

Yes, but often itā€™ll get say 30 files or 50 files and hit that error.

If, say, the first 3 get uploaded before it crashes, then the next time you try a deployment it should skip those, which means that you would get to full deployment eventually.

I donā€™t think thatā€™s happening, but I could be wrong. I re-ran it 10 times and it never successfully deployed past my 50 files. Does that occur even on the first deploy?

I think we probably just need to make Wrangler more resilient to the upload token expiring, renew it more automatically, and try again, without bothering the user.

I feel it may still timeout regardless due to my upload speed, so making the JWT expiration longer would help too. Retrying logic would be fantastic.