From 66db583432ea70d64bfa5d2f7d056e2c8c59b78c Mon Sep 17 00:00:00 2001 From: yusing Date: Thu, 23 Jan 2025 04:41:10 +0800 Subject: [PATCH] fix notification dispatcher panic when dispatching on program exit --- internal/notif/dispatcher.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/notif/dispatcher.go b/internal/notif/dispatcher.go index b354af41..d38d261b 100644 --- a/internal/notif/dispatcher.go +++ b/internal/notif/dispatcher.go @@ -49,7 +49,12 @@ func Notify(msg *LogMessage) { if dispatcher == nil { return } - dispatcher.logCh <- msg + select { + case <-dispatcher.task.Context().Done(): + return + default: + dispatcher.logCh <- msg + } } func (disp *Dispatcher) RegisterProvider(cfg types.NotificationConfig) (Provider, E.Error) {