fix(gs): abort uploads when source reader fails - #1480
Open
UniversePeak wants to merge 2 commits into
Open
Conversation
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
Abort a GCS upload when the source reader returns an error instead of allowing a deferred
Writer.Close()to finalize the partial object under its final LTX key.Problem
gs.ReplicaClient.WriteLTXFile()previously deferredw.Close()immediately after creating the GCS writer. Ifio.Copy()read a partial LTX stream and then returned a source error, the deferred close still completed the GCS write. That could leave a partial object visible at the final LTX path even thoughWriteLTXFile()returned an error.Issue #1263 identifies this path, including the compaction case where an
io.Pipeforwards a source or compaction error after partial output. The issue discussion also confirms that the earlier PR covering this behavior is no longer present and that the issue remains uncovered.Solution
context.WithCancel.NewWriter.io.Copy()failure and return without calling normalClose().Close()only on the successful copy path.Scope
In scope:
WriteLTXFile()failure cleanup.Not in scope:
Test Plan
go test ./gs -run 'TestReplicaClient_(OpenLTXFileReadsFullObject|WriteLTXFileAbortsOnSourceError)$' -count=1go test ./gs -count=1go test ./... -count=1(the GCS package passes; unrelated Windows filesystem/path assumptions cause failures infile,cmd/litestream, andtests/integrationon this host)The focused regression test passes against the fake GCS server. The full test command reaches the changed package successfully but has environment-specific failures involving Windows path semantics, directory syncing, and file locks outside this change.
Fixes #1263