SupportBundles: Recover from Bundler panics gracefully (#60995)

bundler panics should not crash Grafana
This commit is contained in:
Jo 2023-01-05 13:23:35 +00:00 committed by GitHub
parent a9e39a108c
commit fc0926f8fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -118,7 +118,13 @@ func (s *Service) create(ctx context.Context, collectors []string, usr *user.Sig
go func(uid string, collectors []string) {
ctx, cancel := context.WithTimeout(context.Background(), bundleCreationTimeout)
defer cancel()
defer func() {
if err := recover(); err != nil {
s.log.Error("support bundle collection panic", "err", err)
}
cancel()
}()
s.startBundleWork(ctx, collectors, uid)
}(bundle.UID, collectors)

View File

@ -5,14 +5,18 @@ import (
"bytes"
"compress/gzip"
"context"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"runtime/debug"
"github.com/grafana/grafana/pkg/services/supportbundles"
)
var ErrCollectorPanicked = errors.New("collector panicked")
type bundleResult struct {
path string
err error
@ -20,7 +24,15 @@ type bundleResult struct {
func (s *Service) startBundleWork(ctx context.Context, collectors []string, uid string) {
result := make(chan bundleResult)
go func() {
defer func() {
if err := recover(); err != nil {
s.log.Error("support bundle collector panic", "err", err, "stack", string(debug.Stack()))
result <- bundleResult{err: ErrCollectorPanicked}
}
}()
sbFilePath, err := s.bundle(ctx, collectors, uid)
if err != nil {
result <- bundleResult{err: err}