-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
storage: object written to bucket even if Writer.Close fails because of context expiration #4453
Comments
Thank you @nicholas-mainardi for the detailed log. As you suspected, this is likely occurring due to the timeout happening between when the upload is finalized on the server side and when the response is received by the client. There's a background goroutine that monitors when a context is cancelled, either by a timeout or cancellation. It will always honor the Though it’s surprising to see this happen more often than expected from your report. We’re looking into the library with your code to ensure that the cancellation is being honored consistently. Also, checking with the team if there’s ways to better mitigate this problem while using parallel composite uploads. Thanks! |
I'll add that based on your use case, a reasonable workaround might be:
|
Thanks @tritone for the suggestion, that is definitely an interesting workaround for the context timeout issue. Nonetheless, there is probably another case that I experienced where the reported issue with context cancellation may be troublesome: in my implementation, the context may also be canceled to abort the upload operation, and in that case I need to be sure that all the chunks are erased from the bucket. To this extent, I tried to add some delete operations for all chunks in case of context cancellation. However, there seems to be a slack time between when the That being said, I understand that it is difficult to prevent such a race condition, but that seems to happen more happen than expected. Thank you very much for the prompt replies and for checking with the team if this issue can be made much less likely to occur. |
@nicholas-mainardi FYI, we found and fixed another bug in the generated library which may have been exacerbating this issue. See googleapis/google-api-go-client#1364 and googleapis/google-api-go-client#1359. Basically there was a race condition in the check for cancelation which may have allowed requests to be sent after the client should have known that the context was canceled, but this should now be fixed in the most recent storage release. I'm going to close this issue for now, but feel free to re-open or open a new issue if you have further questions. |
I am trying to implement a client application to upload big files to GCS buckets employing parallel composite uploads. To this extent, I split my big file in chunks and upload in parallel each chunk as a separate object, merging then all the chunks with a
Composer
. For each chunk, I create an instance of aWriter
, each with its own context with a given timeout.The problem in such a setting is that sometimes, even if the function
Writer.Close
fails with errorcontext deadline exceeded
, the object is still created in the bucket, which appears to me as an unexpected behavior. This issue seems to be triggered once in a while when some of the chunks being simultaneously uploaded are successfully written to the bucket before context expiration, while others are written even if the context has expired before completion of theWriter.Close
function.I tried to reproduce the issue with a simpler piece of code in my local environment:
Client
Storage
Environment
Linux 5.8.0-59-generic #66~20.04.1-Ubuntu - native installation
Go Environment
$ go version go1.16.3
$ go env GO111MODULE="auto", GOHOSTARCH="amd64", CGO_ENABLED="1"
Code
The
putObjectCopies
function simultaneously uploadsnumCopies
copies of an object with a random payload (the same for each object for simplicity).Expected behavior
Bucket
bucketName
should contain only copies for which thewriter.Close
function terminates without any errorActual behavior
Sometimes the bucket
bucketName
contains also copies for which thewriter.Close
function fails with errorcontext deadline exceeded
. The issue seems to be triggered only when the timeout for the context (uploadTimeout
) is set to a value which allows several uploads of the copies to be completed before context expiration, while other uploads fails due to context expiration while executingwriter.Close
function. For instance, in my local environment, the issue appears withuploadTimeout
set to 33 seconds while uploading 10 copies of an object with 5M random bytes. Note that the issue does not happen in every run of theputObjectCopies
function with some uploads failing and other succeeding: indeed, I had to run multiple times the function before actually observing the issue, as the context expiration must probably occur in a short timeframe between the end of the writing of the object in thewriter.Close
function and the actual end of thewriter.Close
execution.The text was updated successfully, but these errors were encountered: