From d2ae16ad6f19cccfc300b06f2002ba847dead69c Mon Sep 17 00:00:00 2001 From: Krzysztof Tomecki <152964795+chris-4chain@users.noreply.github.com> Date: Thu, 9 Jan 2025 08:20:33 +0100 Subject: [PATCH 1/2] fix(SPV-1357): webhook tests --- engine/notifications/webhook_manager.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/engine/notifications/webhook_manager.go b/engine/notifications/webhook_manager.go index 035b7b9a2..8a097e684 100644 --- a/engine/notifications/webhook_manager.go +++ b/engine/notifications/webhook_manager.go @@ -26,6 +26,7 @@ type WebhookManager struct { banMsg chan string // url notifications *Notifications logger *zerolog.Logger + endMsg chan bool } // NewWebhookManager creates a new WebhookManager. It starts a goroutine which checks for webhook updates. @@ -41,6 +42,7 @@ func NewWebhookManager(ctx context.Context, logger *zerolog.Logger, notification updateMsg: make(chan bool), banMsg: make(chan string), logger: logger, + endMsg: make(chan bool), } go manager.checkForUpdates() @@ -50,7 +52,11 @@ func NewWebhookManager(ctx context.Context, logger *zerolog.Logger, notification // Stop stops the WebhookManager. func (w *WebhookManager) Stop() { + w.ticker.Stop() w.cancelAllFunc() + + <-w.endMsg + w.logger.Info().Msg("WebhookManager stopped") } // Subscribe subscribes to a webhook. It adds the webhook to the database and starts a notifier for it. @@ -100,7 +106,7 @@ func (w *WebhookManager) GetAll(ctx context.Context) ([]ModelWebhook, error) { func (w *WebhookManager) checkForUpdates() { defer func() { - w.logger.Info().Msg("WebhookManager stopped") + w.endMsg <- true if err := recover(); err != nil { w.logger.Warn().Msgf("WebhookManager failed: %v", err) } From 8ad7d45badf0e239c02ebffe2e73b191da1a8f48 Mon Sep 17 00:00:00 2001 From: Krzysztof Tomecki <152964795+chris-4chain@users.noreply.github.com> Date: Thu, 9 Jan 2025 12:21:07 +0100 Subject: [PATCH 2/2] fix(SPV-1357): buffered channel & fatal if panic --- engine/notifications/webhook_manager.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/notifications/webhook_manager.go b/engine/notifications/webhook_manager.go index 8a097e684..1f722158b 100644 --- a/engine/notifications/webhook_manager.go +++ b/engine/notifications/webhook_manager.go @@ -42,7 +42,7 @@ func NewWebhookManager(ctx context.Context, logger *zerolog.Logger, notification updateMsg: make(chan bool), banMsg: make(chan string), logger: logger, - endMsg: make(chan bool), + endMsg: make(chan bool, 1), } go manager.checkForUpdates() @@ -108,7 +108,7 @@ func (w *WebhookManager) checkForUpdates() { defer func() { w.endMsg <- true if err := recover(); err != nil { - w.logger.Warn().Msgf("WebhookManager failed: %v", err) + w.logger.Fatal().Msgf("WebhookManager failed: %v", err) } }()