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

Exit 94 if a mirror lock times out #3023

Merged
merged 1 commit into from
Oct 8, 2024
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
28 changes: 26 additions & 2 deletions internal/job/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,18 @@ func (e *Executor) CheckoutPhase(ctx context.Context) error {
return nil
}

var errLockTimeout ErrTimedOutAcquiringLock
switch {
case shell.IsExitError(err) && shell.GetExitCode(err) == -1:
e.shell.Warningf("Checkout was interrupted by a signal")
r.Break()

case errors.As(err, &errLockTimeout):
e.shell.Warningf("Checkout could not acquire the %s lock before timing out", errLockTimeout.Name)
r.Break()
// 94 chosen by fair die roll
return &shell.ExitError{Code: 94, Err: err}

case errors.Is(err, context.Canceled):
e.shell.Warningf("Checkout was cancelled")
r.Break()
Expand Down Expand Up @@ -304,7 +311,10 @@ func (e *Executor) updateGitMirror(ctx context.Context, repository string) (stri
defer canc()
mirrorCloneLock, err := e.shell.LockFile(cloneCtx, mirrorDir+".clonelock")
if err != nil {
return "", err
if errors.Is(err, context.DeadlineExceeded) {
return "", ErrTimedOutAcquiringLock{Name: "clone", Err: err}
}
return "", fmt.Errorf("unable to acquire clone lock: %w", err)
}
defer mirrorCloneLock.Unlock()

Expand Down Expand Up @@ -343,7 +353,10 @@ func (e *Executor) updateGitMirror(ctx context.Context, repository string) (stri
defer canc()
mirrorUpdateLock, err := e.shell.LockFile(updateCtx, mirrorDir+".updatelock")
if err != nil {
return "", err
if errors.Is(err, context.DeadlineExceeded) {
return "", ErrTimedOutAcquiringLock{Name: "update", Err: err}
}
return "", fmt.Errorf("unable to acquire update lock: %w", err)
}
defer mirrorUpdateLock.Unlock()

Expand Down Expand Up @@ -407,6 +420,17 @@ func (e *Executor) updateGitMirror(ctx context.Context, repository string) (stri
return mirrorDir, nil
}

type ErrTimedOutAcquiringLock struct {
Name string
Err error
}

func (e ErrTimedOutAcquiringLock) Error() string {
return fmt.Sprintf("timed out acquiring %s lock: %v", e.Name, e.Err)
}

func (e ErrTimedOutAcquiringLock) Unwrap() error { return e.Err }

// updateRemoteURL updates the URL for 'origin'. If gitDir == "", it assumes the
// local repo is in the current directory, otherwise it includes --git-dir.
// If the remote has changed, it logs some extra information. updateRemoteURL
Expand Down
4 changes: 2 additions & 2 deletions internal/job/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,8 @@ func (e *Executor) runWrappedShellScriptHook(ctx context.Context, hookName strin
// so it may inform the Buildkite API
if shell.IsExitError(err) {
return &shell.ExitError{
Code: exitCode,
Message: fmt.Sprintf("The %s hook exited with status %d", hookName, exitCode),
Code: exitCode,
Err: fmt.Errorf("The %s hook exited with status %d", hookName, exitCode),
}
}

Expand Down
10 changes: 5 additions & 5 deletions internal/job/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,11 @@ func IsExitError(err error) bool {

// ExitError is an error that carries a shell exit code
type ExitError struct {
Code int
Message string
Code int
Err error
}

// Error returns the string message and fulfils the error interface
func (ee *ExitError) Error() string {
return ee.Message
}
func (ee *ExitError) Error() string { return ee.Err.Error() }

func (ee *ExitError) Unwrap() error { return ee.Err }