fix: fix appendable upload finalization race condition#3295
Merged
BenWhitehead merged 3 commits intomainfrom Sep 16, 2025
Merged
fix: fix appendable upload finalization race condition#3295BenWhitehead merged 3 commits intomainfrom
BenWhitehead merged 3 commits intomainfrom
Conversation
When finalizing an appendable upload depending on how quickly gcs is acking bytes, we could run into a case where finish_write: true was sent before all bytes had been enqueued. Regression introduced in 2.57.0
BenWhitehead
commented
Sep 16, 2025
| if (i < lastIdx && !shouldFlush) { | ||
| appended = stream.append(datum); | ||
| } else if (i == lastIdx && nextWriteShouldFinalize) { | ||
| } else if (i == lastIdx && remainingAfterPacking == 0 && nextWriteShouldFinalize) { |
Collaborator
Author
There was a problem hiding this comment.
These two lines are the actual fix
BenWhitehead
commented
Sep 16, 2025
| totalSentBytes, | ||
| confirmedBytes, | ||
| size | ||
| ); |
Collaborator
Author
There was a problem hiding this comment.
Adding more info to the diagnostic to make it more useful in the future.
BenWhitehead
commented
Sep 16, 2025
| @Rule public final TestName testName = new TestName(); | ||
|
|
||
| @Test | ||
| public void appendAndFinalizeOnlyPerformedIfAllBytesConsumed() throws IOException { |
Collaborator
Author
There was a problem hiding this comment.
The new test to verify the fix
BenWhitehead
commented
Sep 16, 2025
| } | ||
| } | ||
|
|
||
| private static BidiStreamingCallable<BidiWriteObjectRequest, BidiWriteObjectResponse> |
Collaborator
Author
There was a problem hiding this comment.
Moved into BidiUploadTestUtils.java for sharing
Contributor
|
Was this caught somewhere? Is there a bug with context? |
Collaborator
Author
b/445496061 |
ddelgrosso1
approved these changes
Sep 16, 2025
Contributor
ddelgrosso1
left a comment
There was a problem hiding this comment.
LGTM. Sync'd with Ben earlier / was discussed in biweekly.
nidhiii-27
pushed a commit
to nidhiii-27/java-storage
that referenced
this pull request
Oct 6, 2025
When finalizing an appendable upload depending on how quickly gcs is acking bytes, we could run into a case where finish_write: true was sent before all bytes had been enqueued. Regression introduced in 2.57.0
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.
When finalizing an appendable upload depending on how quickly gcs is acking bytes, we could run into a case where finish_write: true was sent before all bytes had been enqueued.
Regression introduced in 2.57.0