From e60efde4d40846c3560d342645d130fad1ab497b Mon Sep 17 00:00:00 2001 From: Deluan Date: Thu, 25 Dec 2025 19:01:41 -0500 Subject: [PATCH] refactor: simplify schedule cloning in Close method and enhance plugin cleanup error handling Signed-off-by: Deluan --- plugins/host_scheduler.go | 6 ++---- plugins/manager.go | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/host_scheduler.go b/plugins/host_scheduler.go index 8271d6465..ffea6cdd0 100644 --- a/plugins/host_scheduler.go +++ b/plugins/host_scheduler.go @@ -3,6 +3,7 @@ package plugins import ( "context" "fmt" + "maps" "sync" "time" @@ -146,10 +147,7 @@ func (s *schedulerServiceImpl) CancelSchedule(ctx context.Context, scheduleID st // This is called when the plugin is unloaded. func (s *schedulerServiceImpl) Close() error { s.mu.Lock() - schedules := make(map[string]*scheduleEntry, len(s.schedules)) - for k, v := range s.schedules { - schedules[k] = v - } + schedules := maps.Clone(s.schedules) s.schedules = make(map[string]*scheduleEntry) s.mu.Unlock() diff --git a/plugins/manager.go b/plugins/manager.go index 4d832b872..09ba92631 100644 --- a/plugins/manager.go +++ b/plugins/manager.go @@ -195,6 +195,10 @@ func (m *Manager) Stop() error { // Close all plugins for name, plugin := range m.plugins { + err := plugin.Close() + if err != nil { + log.Error("Error during plugin cleanup", "plugin", name, err) + } if plugin.compiled != nil { if err := plugin.compiled.Close(context.Background()); err != nil { log.Error("Error closing plugin", "plugin", name, err)