From 6c8ddac6273d57744e771f279e89a2cdee861ec7 Mon Sep 17 00:00:00 2001 From: Quick <31828688+Quick104@users.noreply.github.com> Date: Thu, 28 May 2026 20:37:33 -0400 Subject: [PATCH] revert(startup): keep open-scrobble sweep deferred for fast startup Reverts 7161c86f. Running the sweep synchronously before the listener could add up to 30s to restart-before-playback when a watch provider is unreachable, which regresses the deliberate startup-deferral from dfa0f686. Prefer the fast-startup behavior and accept the small window where a resume immediately after restart may create a duplicate scrobble; the sweep returns to the deferred background-init list. (Panic-safety for that list is added in a follow-up commit.) Per PR #21 review decision. Co-Authored-By: Claude Opus 4.8 (1M context) --- cmd/silo/main.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/cmd/silo/main.go b/cmd/silo/main.go index 78a4bd9e..819ecd96 100644 --- a/cmd/silo/main.go +++ b/cmd/silo/main.go @@ -1023,6 +1023,11 @@ func main() { WithMatcher(historyimport.NewMatcher(historyRepo)). WithWatchState(watchstate.NewService(userStoreProvider).WithStableIdentityResolver(historyIdentity)). WithUserStoreProvider(userStoreProvider) + backgroundInit = append(backgroundInit, func(ctx context.Context) { + if err := watchProviderService.SweepOpenScrobbles(ctx); err != nil { + slog.Warn("failed to sweep open watch provider scrobbles", "error", err) + } + }) } deps.SessionMgr = sessionMgr deps.PlaybackRealtimeHub = playback.NewRealtimeHub() @@ -1678,19 +1683,6 @@ func main() { }() } - // Stop scrobble sessions left open by the previous process BEFORE the - // listener accepts playback requests, so a resume immediately after a - // restart doesn't create overlapping/stale scrobbles on remote providers. - // Bounded by a timeout so an unreachable provider can't hang startup (which - // is why the rest of non-critical init stays deferred below). - if watchProviderService != nil { - sweepCtx, cancelSweep := context.WithTimeout(appCtx, 30*time.Second) - if err := watchProviderService.SweepOpenScrobbles(sweepCtx); err != nil { - slog.Warn("failed to sweep open watch provider scrobbles", "error", err) - } - cancelSweep() - } - errCh := make(chan error, 2) go func() { slog.Info("HTTP server listening", "addr", cfg.Server.Listen)