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

Handle panics in the osbuild job & fix panic when OCI authentication fails #3666

Merged
merged 3 commits into from
Sep 1, 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
22 changes: 15 additions & 7 deletions cmd/osbuild-worker/jobimpl-osbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,28 +278,36 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
}
osbuildJobResult.HostOS = hostOS

var outputDirectory string

// In all cases it is necessary to report result back to osbuild-composer worker API.
defer func() {
if r := recover(); r != nil {
logWithId.Errorf("Recovered from panic: %v", r)

osbuildJobResult.JobError = clienterrors.WorkerClientError(
clienterrors.ErrorJobPanicked,
fmt.Sprintf("job panicked:\n%v\n\noriginal error:\n%v", r, osbuildJobResult.JobError),
nil,
)
}
validateResult(osbuildJobResult, job.Id().String())

err := job.Update(osbuildJobResult)
if err != nil {
logWithId.Errorf("Error reporting job result: %v", err)
}
}()

outputDirectory, err := os.MkdirTemp(impl.Output, job.Id().String()+"-*")
if err != nil {
return fmt.Errorf("error creating temporary output directory: %v", err)
}
defer func() {
err = os.RemoveAll(outputDirectory)
if err != nil {
logWithId.Errorf("Error removing temporary output directory (%s): %v", outputDirectory, err)
}
}()

outputDirectory, err = os.MkdirTemp(impl.Output, job.Id().String()+"-*")
if err != nil {
return fmt.Errorf("error creating temporary output directory: %v", err)
}

// Read the job specification
var jobArgs worker.OSBuildJob
err = job.Args(&jobArgs)
Expand Down
4 changes: 3 additions & 1 deletion internal/upload/oci/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func (c Client) uploadToBucket(objectName string, bucketName string, namespace s
ctx := context.Background()
resp, err := uploadManager.UploadFile(ctx, req)
if err != nil {
if resp.IsResumable() {
// resp.IsResumable crashes if resp.MultipartUploadResponse == nil
// Thus, we need to check for both.
if resp.MultipartUploadResponse != nil && resp.IsResumable() {
resp, err = uploadManager.ResumeUploadFile(ctx, *resp.MultipartUploadResponse.UploadID)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions internal/worker/clienterrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
ErrorOSTreeParamsInvalid ClientErrorCode = 34
ErrorOSTreeDependency ClientErrorCode = 35
ErrorRemoteFileResolution ClientErrorCode = 36
ErrorJobPanicked ClientErrorCode = 37
)

type ClientErrorCode int
Expand Down
Loading