mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SupportBundles: Recover from Bundler panics gracefully (#60995)
bundler panics should not crash Grafana
This commit is contained in:
parent
a9e39a108c
commit
fc0926f8fb
@ -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)
|
||||
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user