fix(01-01): add mutex protection to Queue, Library, and Playlist SetContext methods

- Queue.SetContext acquires existing q.mu before writing q.ctx
- Library struct gets new mu sync.Mutex; SetContext and SetRescanHooks acquire it
- Playlist Service struct gets new mu sync.Mutex; SetContext and SetFavoritesConfig acquire it
- Library and Playlist release lock before calling post-init methods (registerEventHandlers, migrateExistingPlaylists)
This commit is contained in:
2026-02-28 12:09:14 -05:00
parent 4e2986e19c
commit daaa6b7f97
3 changed files with 22 additions and 0 deletions
+10
View File
@@ -11,6 +11,7 @@ import (
"slices"
"strconv"
"strings"
"sync"
"github.com/wailsapp/wails/v2/pkg/runtime"
@@ -96,6 +97,9 @@ type PhantomSearchResult struct {
// Service manages playlist operations.
type Service struct {
// mu protects ctx and favoritesConf from concurrent access
// during initialization.
mu sync.Mutex
ctx context.Context
logger *slog.Logger
db *database.DB
@@ -121,6 +125,9 @@ func NewService(
func (s *Service) SetFavoritesConfig(
provider FavoritesConfigProvider,
) {
s.mu.Lock()
defer s.mu.Unlock()
s.favoritesConf = provider
}
@@ -128,7 +135,10 @@ func (s *Service) SetFavoritesConfig(
// one-time startup migration to bootstrap M3U8 files for
// existing playlists.
func (s *Service) SetContext(ctx context.Context) {
s.mu.Lock()
s.ctx = ctx
s.mu.Unlock()
s.migrateExistingPlaylists()
}