refactor: simplify schedule cloning in Close method and enhance plugin cleanup error handling

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan 2025-12-25 19:01:41 -05:00
parent e200b70ea6
commit e60efde4d4
2 changed files with 6 additions and 4 deletions

View File

@ -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()

View File

@ -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)