[wrangler] Reduce Pipelines S3 bundle size - #15414
james-elicx wants to merge 1 commit into
Conversation
|
| try { | ||
| const response = await fetch(signedRequest.url, { | ||
| method: signedRequest.method, | ||
| headers: Object.fromEntries(signedRequest.headers), | ||
| redirect: "manual", | ||
| }); | ||
| await response.arrayBuffer(); | ||
|
|
||
| if (response.ok) { | ||
| return; | ||
| } | ||
|
|
||
| const error = new R2RequestError(response.status, response.statusText); | ||
| if ( | ||
| attempt === MAX_ATTEMPTS || | ||
| !RETRYABLE_STATUS_CODES.has(response.status) | ||
| ) { | ||
| throw error; | ||
| } | ||
| } catch (error) { | ||
| if ( | ||
| attempt === MAX_ATTEMPTS || | ||
| (error instanceof R2RequestError && | ||
| !RETRYABLE_STATUS_CODES.has(error.status)) | ||
| ) { | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| const maximumDelay = INITIAL_RETRY_DELAY_MS * 2 ** (attempt - 1); | ||
| await setTimeout(Math.random() * maximumDelay); |
There was a problem hiding this comment.
The AWS SDK retry strategy honors Retry-After, but this replacement retries a throttled request within at most 300 ms. R2/Cloudflare rate-limit responses can direct clients to wait longer, so verifyR2Credentials() can now reject valid credentials instead of performing its prior retry behavior.
| try { | |
| const response = await fetch(signedRequest.url, { | |
| method: signedRequest.method, | |
| headers: Object.fromEntries(signedRequest.headers), | |
| redirect: "manual", | |
| }); | |
| await response.arrayBuffer(); | |
| if (response.ok) { | |
| return; | |
| } | |
| const error = new R2RequestError(response.status, response.statusText); | |
| if ( | |
| attempt === MAX_ATTEMPTS || | |
| !RETRYABLE_STATUS_CODES.has(response.status) | |
| ) { | |
| throw error; | |
| } | |
| } catch (error) { | |
| if ( | |
| attempt === MAX_ATTEMPTS || | |
| (error instanceof R2RequestError && | |
| !RETRYABLE_STATUS_CODES.has(error.status)) | |
| ) { | |
| throw error; | |
| } | |
| } | |
| const maximumDelay = INITIAL_RETRY_DELAY_MS * 2 ** (attempt - 1); | |
| await setTimeout(Math.random() * maximumDelay); | |
| let retryAfterMs = 0; | |
| try { | |
| const response = await fetch(signedRequest.url, { | |
| method: signedRequest.method, | |
| headers: Object.fromEntries(signedRequest.headers), | |
| redirect: "manual", | |
| }); | |
| await response.arrayBuffer(); | |
| if (response.ok) { | |
| return; | |
| } | |
| const retryAfter = response.headers.get("retry-after"); | |
| if (retryAfter !== null) { | |
| const retryAfterSeconds = Number(retryAfter); | |
| if (Number.isNaN(retryAfterSeconds)) { | |
| const retryAfterDate = new Date(retryAfter).getTime(); | |
| if (!Number.isNaN(retryAfterDate)) { | |
| retryAfterMs = Math.max(0, retryAfterDate - Date.now()); | |
| } | |
| } else { | |
| retryAfterMs = retryAfterSeconds * 1000; | |
| } | |
| } | |
| const error = new R2RequestError(response.status, response.statusText); | |
| if ( | |
| attempt === MAX_ATTEMPTS || | |
| !RETRYABLE_STATUS_CODES.has(response.status) | |
| ) { | |
| throw error; | |
| } | |
| } catch (error) { | |
| if ( | |
| attempt === MAX_ATTEMPTS || | |
| (error instanceof R2RequestError && | |
| !RETRYABLE_STATUS_CODES.has(error.status)) | |
| ) { | |
| throw error; | |
| } | |
| } | |
| const maximumDelay = INITIAL_RETRY_DELAY_MS * 2 ** (attempt - 1); | |
| await setTimeout(Math.max(retryAfterMs, Math.random() * maximumDelay)); |
|
I'm Bonk, and I've done a quick review of your PR. Replaces Pipelines S3 validation with a lightweight SigV4 R2 client.
|
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/codemods
@cloudflare/config
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-plugin
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
Fixes no linked issue.
Wrangler's Pipelines credential validation only uses S3
HeadBucketandListObjectsV2withMaxKeys: 1, but importingS3Clientpulls 1,234,988 bytes of AWS and Smithy code into the published CLI bundle, including credential-provider paths that cannot be reached because Pipelines always supplies credentials and an endpoint explicitly.This replaces that runtime client with a minimal R2 client built on
aws4fetch's low-level SigV4 signer and Wrangler's existingundicifetch. It preserves path-style bucket URLs,auto/s3signing scope, the empty-payload SHA-256 header, non-success failures, manual redirect handling, response-body disposal, and the SDK's default three attempts for network, throttling, and transient server failures. The existing outer propagation retry for newly created service tokens is unchanged.Bundle measurements
Measurements use equivalent source-map-disabled Wrangler builds from the same checkout.
cli.jsThe emitted metafile's AWS/Smithy contribution falls from 1,234,988 bytes across 751 inputs to zero.
aws4fetchcontributes 10,405 bytes.Validation
pnpm --dir packages/wrangler exec vitest run src/__tests__/pipelines-r2-client.test.ts src/__tests__/pipelines-setup.test.ts— 27 passedpnpm --dir packages/wrangler check:typepnpm --dir packages/wrangler type:testsSOURCEMAPS=false pnpm run build --filter wrangler --forcepnpm run check --filter wranglerNote
This is a contribution from an AI agent: Codex.