Repository navigation
Conversation
The PDF.js fallback threw on an error status or an oversize declared Content-Length without cancelling the response body, so the rejected stream stayed open while the error view was shown. Cancel it before throwing, without letting a failed cancel replace the visible error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — Rejected PDF downloads now release their response bodies without changing preview limits or error behavior. The change is limited to resource cleanup and presents no obvious material risk. You can add or adjust custom eligibility rules. Learn more. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Note Written by Verified in a real dev environmentverified as-is at used the real web client, repo playwright and opened the documents through the files panel, which reaches these are local browser observations, not a remote bandwidth benchmark. the visible error remains unchanged. cancellation also works on retry. the small pdf still renders both pages; next page, zoom, find with one highlighted match, and switching back from a rejected document all work. blacksmith passed the existing helper tests (2 cases), the existing pdf viewer browser test, and before, main: after, pr: Not verified
|
|
Note 🤖 Opus 5.5 replying on behalf of Victor. @maria-rcks thanks for the test; it showed the head cancelling the too-large 200 download in the real files panel. For the open item we put a local proxy in front of the dev server that answered one PDF with a 503 and a 64 MiB body, then opened that PDF from the files panel in Chrome 158 on Linux on main |



Problem
When the PDF.js fallback loads a PDF,
readBoundedDocumentrejects a response with an error status or a declaredContent-Lengthover the 50 MiB limit. It throws without cancelling the response body. Nothing reads or cancels that body afterwards, and the viewer clears its timeout and shows the error. So the browser keeps downloading the file it already refused, until the viewer unmounts, retries or switches source.In Chromium, after the "unavailable or too large" error appeared, a 50 MiB + 1 byte response still downloaded in full. The existing check for a body that grows past the limit while streaming already cancels its reader. Only the early rejection missed it.
Change
Cancel the response body before throwing on those two early checks. The cancel isn't awaited and its rejection is ignored, so a slow or failing cancel can't delay or replace the error the viewer shows. The limit, the messages and the streamed-read path are unchanged.
Scope and approval
A small fix for an obvious resource bug, under the obvious-bug exception. It adds one cancel call to the PDF fallback's fetch helper, plus a test. The native browser PDF viewer doesn't use this helper and is unaffected.
The font preview (
readFontinFontViewer.tsx) and the large-text worker's error-status check have the same early-rejection pattern. I left them out to keep this PR to one change. I can fold them in or send them separately.Verification
readBoundedDocument.test.tscovers an error status and a declared oversize body. Each row checks the body'scancelruns and the existing error still comes through whencancelthrows. Both rows fail onmain. Without the.catch, the run reports unhandled rejections.fetchshowed the connection closed after the fix and held open before it.mainthe request stayed open after the error until the viewer closed: about 7 MB taken withno-store, about 58 MB within a second withprivate, max-age=3600. On this branch it was cancelled (net::ERR_ABORTED,canceled: true) 1 to 2 ms after the 503 headers, on first open and on Try again, with the same error text.PdfViewer.browser.test.tsxpasses.vp run check:changedpasses.Not checked:
Prior PRs
#21469 added this helper with the other document previews. #25496 also edits
PdfViewer.tsxand doesn't touch this helper. I found no open PR that changes this file.Generated with Claude Opus 5.5 in T3 Code Nightly