fix(workspaces): send content-length for R2 processor requests#647
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(workspaces): send content-length for R2 processor requests#647posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
The R2 storage migration (31e5e0f) started streaming the R2 object body straight to the file processor with duplex: "half" but only a custom x-file-size header. Cloudflare Workers refuses to send a streamed request body without a known length, so every preview generation threw `TypeError: Provided readable stream must have a known length`. Declare the length via the standard content-length header using the already-threaded verified sizeBytes. This covers all processor paths (/preview/*, /parse/pdf, /validate/pdf) since they share the helper. Generated-By: PostHog Code Task-Id: 571bc333-acb2-4fc8-b784-76b09256b91d
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The R2 storage migration (
31e5e0f6) started streaming the R2 object body directly to the workspace file processor withduplex: "half", but the request only carried a customx-file-sizeheader — nevercontent-length. Cloudflare Workers refuses to send a streamed request body without a known length, sorequestWorkspaceFileProcessorthrewTypeError: Provided readable stream must have a known lengthon every preview request, breaking PDF/image preview generation completely.The fix declares the length via the standard
content-lengthheader, using thesizeBytesalready threaded through from the source object's verified size. Because all processor paths (/preview/image,/preview/pdf,/parse/pdf,/validate/pdf) share this helper, they're all covered by the single change. Added a focused test asserting the outgoing request carriescontent-length.Why
Freshly deployed production regression: workspace file preview generation was failing 100% of the time for PDF and image uploads, surfacing in error tracking within the first hour of the deploy.
Created with PostHog Code from an inbox report.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.