Skip to content
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

Clean-retry on "fatal: bad object" #2218

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/job/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,8 @@ func (e *Executor) CheckoutPhase(ctx context.Context) error {
switch ge.Type {
// These types can fail because of corrupted checkouts
case gitErrorClean, gitErrorCleanSubmodules, gitErrorClone,
gitErrorCheckoutRetryClean, gitErrorFetchRetryClean:
gitErrorCheckoutRetryClean, gitErrorFetchRetryClean,
gitErrorFetchBadObject:
// Otherwise, don't clean the checkout dir
default:
return err
Expand Down
11 changes: 11 additions & 0 deletions internal/job/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
gitErrorClone
gitErrorFetch
gitErrorFetchRetryClean
gitErrorFetchBadObject
gitErrorClean
gitErrorCleanSubmodules
)
Expand Down Expand Up @@ -139,6 +140,16 @@ func gitFetch(ctx context.Context, sh shellRunner, gitFetchFlags, repository str
}

if err := sh.Run(ctx, "git", commandArgs...); err != nil {
// "fatal: bad object" can happen when the local repo in the checkout
// directory is corrupted, not just the remote or the mirror.
// When using git mirrors, the existing checkout directory might have a
// reference to an object that it expects in the mirror, but the mirror
// no longer contains it (for whatever reason).
// See the NOTE under --shared at https://git-scm.com/docs/git-clone.
if strings.HasPrefix(err.Error(), "fatal: bad object") {
return &gitError{error: err, Type: gitErrorFetchBadObject}
}

// 128 is extremely broad, but it seems permissions errors, network unreachable errors etc, don't result in it
if exitErr := new(exec.ExitError); errors.As(err, &exitErr) && exitErr.ExitCode() == 128 {
return &gitError{error: err, Type: gitErrorFetchRetryClean}
Expand Down