From fb285930c06d92bdf9305272d7bcc4b5a730767b Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Thu, 23 Nov 2023 22:45:31 +0100 Subject: [PATCH] Avoid double closing of export progress channel --- backends/deezer/deezer.go | 2 -- backends/funkwhale/funkwhale.go | 2 -- backends/listenbrainz/listenbrainz.go | 2 -- backends/maloja/maloja.go | 1 - backends/scrobblerlog/scrobblerlog.go | 1 - backends/spotify/spotify.go | 2 -- backends/subsonic/subsonic.go | 1 - cmd/listens.go | 1 + cmd/loves.go | 1 + 9 files changed, 2 insertions(+), 11 deletions(-) diff --git a/backends/deezer/deezer.go b/backends/deezer/deezer.go index 0c2fa63..4420da8 100644 --- a/backends/deezer/deezer.go +++ b/backends/deezer/deezer.go @@ -71,7 +71,6 @@ func (b *DeezerApiBackend) ExportListens(oldestTimestamp time.Time, results chan perPage := MaxItemsPerGet defer close(results) - defer close(progress) p := models.Progress{Total: int64(perPage)} var totalCount int @@ -139,7 +138,6 @@ func (b *DeezerApiBackend) ExportLoves(oldestTimestamp time.Time, results chan m perPage := MaxItemsPerGet defer close(results) - defer close(progress) p := models.Progress{Total: int64(perPage)} var totalCount int diff --git a/backends/funkwhale/funkwhale.go b/backends/funkwhale/funkwhale.go index 604c697..1437c0c 100644 --- a/backends/funkwhale/funkwhale.go +++ b/backends/funkwhale/funkwhale.go @@ -47,7 +47,6 @@ func (b *FunkwhaleApiBackend) ExportListens(oldestTimestamp time.Time, results c perPage := MaxItemsPerGet defer close(results) - defer close(progress) // We need to gather the full list of listens in order to sort them listens := make(models.ListensList, 0, 2*perPage) @@ -97,7 +96,6 @@ func (b *FunkwhaleApiBackend) ExportLoves(oldestTimestamp time.Time, results cha perPage := MaxItemsPerGet defer close(results) - defer close(progress) // We need to gather the full list of listens in order to sort them loves := make(models.LovesList, 0, 2*perPage) diff --git a/backends/listenbrainz/listenbrainz.go b/backends/listenbrainz/listenbrainz.go index efee9bf..af2dea2 100644 --- a/backends/listenbrainz/listenbrainz.go +++ b/backends/listenbrainz/listenbrainz.go @@ -51,7 +51,6 @@ func (b *ListenBrainzApiBackend) ExportListens(oldestTimestamp time.Time, result totalDuration := startTime.Sub(oldestTimestamp) defer close(results) - defer close(progress) // FIXME: Optimize by fetching the listens in reverse listen time order listens := make(models.ListensList, 0, 2*MaxItemsPerGet) @@ -140,7 +139,6 @@ func (b *ListenBrainzApiBackend) ImportListens(export models.ListensResult, impo func (b *ListenBrainzApiBackend) ExportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.Progress) { offset := 0 defer close(results) - defer close(progress) loves := make(models.LovesList, 0, 2*MaxItemsPerGet) p := models.Progress{} diff --git a/backends/maloja/maloja.go b/backends/maloja/maloja.go index 9c2c4fe..6bb3364 100644 --- a/backends/maloja/maloja.go +++ b/backends/maloja/maloja.go @@ -50,7 +50,6 @@ func (b *MalojaApiBackend) ExportListens(oldestTimestamp time.Time, results chan perPage := MaxItemsPerGet defer close(results) - defer close(progress) // We need to gather the full list of listens in order to sort them listens := make(models.ListensList, 0, 2*perPage) diff --git a/backends/scrobblerlog/scrobblerlog.go b/backends/scrobblerlog/scrobblerlog.go index f4a7681..2cae24d 100644 --- a/backends/scrobblerlog/scrobblerlog.go +++ b/backends/scrobblerlog/scrobblerlog.go @@ -100,7 +100,6 @@ func (b *ScrobblerLogBackend) FinishImport() error { func (b *ScrobblerLogBackend) ExportListens(oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.Progress) { defer close(results) - defer close(progress) file, err := os.Open(b.filePath) if err != nil { progress <- models.Progress{}.Complete() diff --git a/backends/spotify/spotify.go b/backends/spotify/spotify.go index ee59b5a..cd01b4f 100644 --- a/backends/spotify/spotify.go +++ b/backends/spotify/spotify.go @@ -89,7 +89,6 @@ func (b *SpotifyApiBackend) ExportListens(oldestTimestamp time.Time, results cha totalDuration := startTime.Sub(oldestTimestamp) defer close(results) - defer close(progress) p := models.Progress{Total: int64(totalDuration.Seconds())} @@ -153,7 +152,6 @@ func (b *SpotifyApiBackend) ExportLoves(oldestTimestamp time.Time, results chan perPage := MaxItemsPerGet defer close(results) - defer close(progress) p := models.Progress{Total: int64(perPage)} var totalCount int diff --git a/backends/subsonic/subsonic.go b/backends/subsonic/subsonic.go index ba88146..a2216f6 100644 --- a/backends/subsonic/subsonic.go +++ b/backends/subsonic/subsonic.go @@ -46,7 +46,6 @@ func (b *SubsonicApiBackend) FromConfig(config *viper.Viper) models.Backend { func (b *SubsonicApiBackend) ExportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.Progress) { defer close(results) - defer close(progress) err := b.client.Authenticate(b.password) if err != nil { progress <- models.Progress{}.Complete() diff --git a/cmd/listens.go b/cmd/listens.go index a7a9287..9bc6945 100644 --- a/cmd/listens.go +++ b/cmd/listens.go @@ -77,6 +77,7 @@ var listensCmd = &cobra.Command{ resultChan := make(chan models.ImportResult) go backends.ProcessListensImports(importBackend, listensChan, resultChan, importProgress) result := <-resultChan + close(exportProgress) wg.Wait() progress.Wait() if result.Error != nil { diff --git a/cmd/loves.go b/cmd/loves.go index e8759d8..29fd625 100644 --- a/cmd/loves.go +++ b/cmd/loves.go @@ -77,6 +77,7 @@ var lovesCmd = &cobra.Command{ resultChan := make(chan models.ImportResult) go backends.ProcessLovesImports(importBackend, lovesChan, resultChan, importProgress) result := <-resultChan + close(exportProgress) wg.Wait() progress.Wait() if result.Error != nil {