Skip to content

Phone uploads: a too-large file gets its 413, not a dropped connection - #33

Merged
ghosthack merged 1 commit into
mainfrom
claude/upload-limit-flake
Nov 26, 2026
Merged

ghosthack merged 1 commit into
mainfrom
claude/upload-limit-flake

Conversation

@ghosthack

Copy link
Copy Markdown
Owner

Fixes the flaky PhoneServerTest.anUploadNeedsTheSecretAndFitsTheLimit. It failed on main on Nov 21 and on #32's first macOS run.

Cause
The server refused an oversized upload on its Content-Length without reading the body. Java's built-in HTTP server sends no response until the request body has been read. When it closes a connection with bytes still unread, the OS resets the connection. Depending on timing, the reset can arrive before the 413 does, and the client then sees header parser received no bytes. A phone uploading a file over 25 MB could hit the same race and get a vague network error instead of the "too large" message.

Changes

  • Server: before answering 413, it reads and drops the rest of a refused body, up to 2× the limit. This applies both to the Content-Length check and to the counted (chunked) path.
  • Phone page: app.js checks the file size before sending and says the file is too large, so a browser never sends one. A new test keeps MAX_UPLOAD_BYTES in app.js equal to PhoneUploads.MAX_BYTES.

Testing

  • mvn -pl app -am test: 640 tests pass.
  • PhoneServerTest: 15/15 runs pass.
  • Stress check, not committed: sending the oversized upload 40 times in one test run reproduced header parser received no bytes in 2 out of 2 runs against the old server, and passed 2 out of 2 runs (80 uploads, all answered 413) with this change.
  • The page's size check hasn't been tried in a real phone browser.

🤖 Generated with Claude Code

The server refused an oversized upload without reading its body. Java's HTTP
server sends nothing until the body is read, and closing on unread bytes resets
the connection, so the client could lose the answer and see only a dropped
connection. That is what made PhoneServerTest.anUploadNeedsTheSecretAndFitsTheLimit
flaky on CI.

- The server now reads and drops the rest of a refused body (up to twice the
  limit) before answering 413.
- The phone page checks the file size before sending and says the file is too
  large, so a browser never sends one; a test keeps its limit equal to the server's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ghosthack
ghosthack merged commit 2794579 into main Nov 26, 2026
3 checks passed
@ghosthack
ghosthack deleted the claude/upload-limit-flake branch November 26, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant