From b8a9c50d6cea3fd38866c5a6eaa6337db6562cde Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Nov 2022 14:24:14 -0700 Subject: [PATCH 1/2] panichandler: process panic handlers in the same go routine --- pkg/panichandler/panichandler.go | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/pkg/panichandler/panichandler.go b/pkg/panichandler/panichandler.go index 31329de4cc..4af60cd849 100644 --- a/pkg/panichandler/panichandler.go +++ b/pkg/panichandler/panichandler.go @@ -78,29 +78,20 @@ func (r *PanicHandlerRegistry) RegisterPanicHandler(ph PanicHandler) { // Crash invokes each of the registered panic handler and then rethrows panic - shutting down the app. func (r *PanicHandlerRegistry) Crash(v interface{}) { stackTrace := Capture() - waitCh := make(chan struct{}) - - go crashOnce.Do(func() { + crashOnce.Do(func() { r.mutex.RLock() defer r.mutex.RUnlock() - wg := sync.WaitGroup{} - wg.Add(len(r.Handlers)) + + go func() { + // terminate the app after 5 seconds in case the panic handler is stuck + time.Sleep(5 * time.Second) + panic(v) + }() for _, handler := range r.Handlers { - h := handler - go func() { - defer wg.Done() - h(v, stackTrace) - }() + handler(v, stackTrace) } - wg.Wait() - close(waitCh) }) - - select { - case <-waitCh: - case <-time.After(5 * time.Second): - } panic(v) } From 1cb212e56fe20be2552cade4032c4ce900a161b7 Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Nov 2022 14:34:05 -0700 Subject: [PATCH 2/2] skip sending stacktrace as a breadcrumb in sentry --- .../aperture-plugin-sentry/sentry/sentrywriter.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/plugins/service/aperture-plugin-sentry/sentry/sentrywriter.go b/plugins/service/aperture-plugin-sentry/sentry/sentrywriter.go index c1aa0342d5..cf06ef4543 100644 --- a/plugins/service/aperture-plugin-sentry/sentry/sentrywriter.go +++ b/plugins/service/aperture-plugin-sentry/sentry/sentrywriter.go @@ -122,7 +122,7 @@ func bytesToStrUnsafe(data []byte) string { } // sentryPanicHandler is a panic handler that sends the fatal level event to Sentry with diagnostic information. -func (s *SentryWriter) sentryPanicHandler(e interface{}, stacktrace panichandler.Callstack) { +func (s *SentryWriter) sentryPanicHandler(e interface{}, _ panichandler.Callstack) { duration, _ := time.ParseDuration(SentryFlushWait) // Crash Log @@ -216,14 +216,6 @@ func (s *SentryWriter) sentryPanicHandler(e interface{}, stacktrace panichandler }) } - // Stacktrace - sentry.AddBreadcrumb(&sentry.Breadcrumb{ - Type: "debug", - Category: "Stacktrace", - Level: sentry.LevelInfo, - Data: stacktrace.GetEntries(), - }) - sentry.CurrentHub().Recover(e) sentry.Flush(duration) }