From da9d9aaf52e30518476f68debc73b5c63a9261cd Mon Sep 17 00:00:00 2001 From: Martin Tomazic Date: Mon, 20 Jan 2025 20:14:36 +0100 Subject: [PATCH] Fixup: Use same channel for clean-up and download --- go/runtime/bundle/manager.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/go/runtime/bundle/manager.go b/go/runtime/bundle/manager.go index 390f154409b..c4a764f088f 100644 --- a/go/runtime/bundle/manager.go +++ b/go/runtime/bundle/manager.go @@ -68,10 +68,9 @@ type Manager struct { runtimeBaseURLs map[common.Namespace][]string globalBaseURLs []string - downloadCh chan struct{} - downloadQueue map[common.Namespace][]hash.Hash - cleanupCh chan struct{} - cleanupQueue map[common.Namespace]version.Version + downloadAndCleanCh chan struct{} + downloadQueue map[common.Namespace][]hash.Hash + cleanupQueue map[common.Namespace]version.Version client *http.Client store ManifestStore @@ -127,9 +126,8 @@ func NewManager(dataDir string, runtimeIDs []common.Namespace, store ManifestSto runtimeIDs: runtimes, globalBaseURLs: globalBaseURLs, runtimeBaseURLs: runtimeBaseURLs, - downloadCh: make(chan struct{}, 1), + downloadAndCleanCh: make(chan struct{}, 1), downloadQueue: make(map[common.Namespace][]hash.Hash), - cleanupCh: make(chan struct{}, 1), cleanupQueue: make(map[common.Namespace]version.Version), client: &client, store: store, @@ -202,15 +200,13 @@ func (m *Manager) run(ctx context.Context) { for { select { case <-ticker.C: - case <-m.downloadCh: - case <-m.cleanupCh: - m.Clean() - continue + case <-m.downloadAndCleanCh: case <-ctx.Done(): m.logger.Info("stopping") return } + m.Clean() m.download() } } @@ -249,9 +245,9 @@ func (m *Manager) Download(runtimeID common.Namespace, manifestHashes []hash.Has } m.downloadQueue[runtimeID] = hashes - // Trigger immediate download of new bundles. + // Trigger immediate download and clean-up of stale bundles. select { - case m.downloadCh <- struct{}{}: + case m.downloadAndCleanCh <- struct{}{}: default: } } @@ -265,9 +261,9 @@ func (m *Manager) Cleanup(runtimeID common.Namespace, active version.Version) { m.cleanupQueue[runtimeID] = active - // Trigger immediate clean-up of stale bundles. + // Trigger immediate download and clean-up of stale bundles. select { - case m.cleanupCh <- struct{}{}: + case m.downloadAndCleanCh <- struct{}{}: default: } }