SupportBundles: Recover from Bundler panics gracefully (#60995)
bundler panics should not crash Grafana
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user