Skip to content

Commit

Permalink
fix: handle worker panics (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
raffis authored Sep 30, 2024
1 parent 96adac6 commit 7590e93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions internal/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package action

import (
"context"
"fmt"
"io"
"os"
"runtime/debug"

"github.com/alitto/pond"
"github.com/doodlescheduling/flux-build/internal/build"
Expand Down Expand Up @@ -32,14 +34,19 @@ func (a *Action) Run(ctx context.Context) error {
defer cancel()

errs := make(chan error)
panicHandler := func(panic interface{}) {
errs <- fmt.Errorf("worker exits from a panic: %v\nStack trace: %s\n", panic, string(debug.Stack()))
}

var lastErr error
helmResultPool := pond.New(1, 1, pond.Context(ctx))
kustomizePool := pond.New(len(a.Paths), len(a.Paths), pond.Context(ctx))
helmPool := pond.New(a.Workers, a.Workers, pond.Context(ctx))
resourcePool := pond.New(1, 1, pond.Context(ctx))
helmResultPool := pond.New(1, 1, pond.Context(ctx), pond.PanicHandler(panicHandler))
kustomizePool := pond.New(len(a.Paths), len(a.Paths), pond.Context(ctx), pond.PanicHandler(panicHandler))
helmPool := pond.New(a.Workers, a.Workers, pond.Context(ctx), pond.PanicHandler(panicHandler))
resourcePool := pond.New(1, 1, pond.Context(ctx), pond.PanicHandler(panicHandler))

defer func() {
if lastErr != nil && !a.AllowFailure {
fmt.Fprintln(os.Stderr, lastErr.Error())
os.Exit(1)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion internal/build/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func (h *Helm) buildFromHelmRepository(ctx context.Context, obj *sourcev1beta2.H
var chartRepo repository.Downloader
repoCacheKey := CacheKey{Repo: normalizedURL}
r, ok := h.repoCache.GetOrLock(repoCacheKey)
if ok {
if ok && r != nil {
chartRepo = r.(repository.Downloader)
}

Expand Down

0 comments on commit 7590e93

Please sign in to comment.