Fix truncated Storage uploads after retrying the final chunk - #8614
tyler-besimple wants to merge 2 commits into
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
A failed final upload request can leave more than 256 KiB buffered after the input stream has reached EOF.
uploadChunk()resets the retry size to 256 KiB, but uses EOF alone to decide whether to finalize the request and report success. The smaller retry can therefore finalize a truncated object while buffered bytes remain unsent.Finalize only when the stream has reached EOF and the current request includes all remaining buffered bytes. Use that same condition when deciding whether to advance the buffer or complete the task.
Added two deterministic regression tests through
putBytes()with mocked HTTP connections: a failed final request that stores no bytes, and one that stores 256 KiB before failing. The tests verify status recovery, upload offsets, complete byte-for-byte payloads, transferred-byte counts, and returned metadata sizes.For the 1,310,843-byte test payload, the original code reports success after storing only 1,048,576 bytes or 1,310,720 bytes, respectively. Both tests pass with the fix.
Related to #6187. This reproduces a specific truncation mechanism; it does not establish that every report in that issue has the same cause.
Validation:
./gradlew :firebase-storage:spotlessApply: passed../gradlew :firebase-storage:check: passed (124 debug tests and 124 release tests, no failures or skips; lint and formatting checks passed).git diff --check: passed.Validation used Java 17, Android API 34, and the repository-supported
subprojects.local.cfgsubset for Storage and its build tooling. No public APIs or dependencies changed.