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) {
|
go func(uid string, collectors []string) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), bundleCreationTimeout)
|
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)
|
s.startBundleWork(ctx, collectors, uid)
|
||||||
}(bundle.UID, collectors)
|
}(bundle.UID, collectors)
|
||||||
|
|
||||||
|
@ -5,14 +5,18 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime/debug"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles"
|
"github.com/grafana/grafana/pkg/services/supportbundles"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrCollectorPanicked = errors.New("collector panicked")
|
||||||
|
|
||||||
type bundleResult struct {
|
type bundleResult struct {
|
||||||
path string
|
path string
|
||||||
err error
|
err error
|
||||||
@ -20,7 +24,15 @@ type bundleResult struct {
|
|||||||
|
|
||||||
func (s *Service) startBundleWork(ctx context.Context, collectors []string, uid string) {
|
func (s *Service) startBundleWork(ctx context.Context, collectors []string, uid string) {
|
||||||
result := make(chan bundleResult)
|
result := make(chan bundleResult)
|
||||||
|
|
||||||
go func() {
|
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)
|
sbFilePath, err := s.bundle(ctx, collectors, uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result <- bundleResult{err: err}
|
result <- bundleResult{err: err}
|
||||||
|
Loading…
Reference in New Issue
Block a user