fix(core): fix Content-Length mismatch in resumable upload initiation#25888
Open
buzz-watcha wants to merge 1 commit intogoogleapis:mainfrom
Open
fix(core): fix Content-Length mismatch in resumable upload initiation#25888buzz-watcha wants to merge 1 commit intogoogleapis:mainfrom
buzz-watcha wants to merge 1 commit intogoogleapis:mainfrom
Conversation
The `initiate_resumable_upload` method was setting the `Content-Length` header to `upload_io.size` (the total file size), but the request body only contains small JSON metadata. This worked with the previous HTTPClient backend because HTTPClient auto-recalculates `Content-Length` from the actual body. However, after the Faraday migration (googleapis#23524), HTTP adapters like Excon respect user-set headers as-is, causing a deadlock: the server waits for more data matching the large `Content-Length`, while the client waits for a response. Fix: Remove the incorrect `Content-Length` header (let the HTTP adapter compute it from the body) and use `X-Upload-Content-Length` to communicate the total file size per the resumable upload protocol. ref: https://cloud.google.com/storage/docs/performing-resumable-uploads
|
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. |
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
initiate_resumable_uploadsets theContent-Lengthheader toupload_io.size(the total file size), but the actual request body is only small JSON metadata.This worked with the previous HTTPClient backend because HTTPClient auto-recalculates
Content-Lengthfrom the actual body size. However, after the Faraday migration (#23524), HTTP adapters like Excon respect user-set headers as-is, causing a deadlock:Content-Length: <file size>but body is only small JSON metadataContent-Lengthread_timeoutis reachedThis issue does not reproduce with
faraday-net_http(the default adapter) becauseNet::HTTPalso auto-recalculatesContent-Length, but it affects any adapter that respects user-set headers (e.g.faraday-excon).Fix
Content-Lengthheader from the initiate request (let the HTTP adapter compute it from the body)X-Upload-Content-Lengthto communicate the total file size, per the resumable upload protocolTest plan
storage_upload_spec.rbtests pass (32 examples, 0 failures)X-Upload-Content-Lengthheader is sent in initiate requestgoogle-cloud-storage1.58.0 +google-apis-core1.0.2 +faraday-excon2.1.0