From c4ef1a24c0ef58adf29beb9bce3c2a41545b07db Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Tue, 7 Feb 2023 15:35:45 +0100 Subject: [PATCH] fix(GODT-2347): Prevent updates from being dropped if goroutine doesn't start fast If the install handler goroutine is busy, the update is dropped. This was intended to prevent two installs from happening at once. However, it also means that updates can be dropped at startup if the goroutine isn't spawned soon enough. A fix is to allow all jobs through and just reject ones that are for an old version. --- internal/bridge/updates.go | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/internal/bridge/updates.go b/internal/bridge/updates.go index 9b0ea252..4208ce5c 100644 --- a/internal/bridge/updates.go +++ b/internal/bridge/updates.go @@ -32,19 +32,7 @@ func (bridge *Bridge) CheckForUpdates() { } func (bridge *Bridge) InstallUpdate(version updater.VersionInfo) { - log := logrus.WithFields(logrus.Fields{ - "version": version.Version, - "current": bridge.curVersion, - "channel": bridge.vault.GetUpdateChannel(), - }) - - select { - case bridge.installCh <- installJob{version: version, silent: false}: - log.Info("The update will be installed manually") - - default: - log.Info("An update is already being installed") - } + bridge.installCh <- installJob{version: version, silent: false} } func (bridge *Bridge) handleUpdate(version updater.VersionInfo) { @@ -89,17 +77,7 @@ func (bridge *Bridge) handleUpdate(version updater.VersionInfo) { default: safe.RLock(func() { - if version.Version.GreaterThan(bridge.newVersion) { - log.Info("An update is available") - - select { - case bridge.installCh <- installJob{version: version, silent: true}: - log.Info("The update will be installed silently") - - default: - log.Info("An update is already being installed") - } - } + bridge.installCh <- installJob{version: version, silent: true} }, bridge.newVersionLock) } } @@ -117,6 +95,12 @@ func (bridge *Bridge) installUpdate(ctx context.Context, job installJob) { "channel": bridge.vault.GetUpdateChannel(), }) + if !job.version.Version.GreaterThan(bridge.newVersion) { + return + } + + log.WithField("silent", job.silent).Info("An update is available") + bridge.publish(events.UpdateAvailable{ Version: job.version, Compatible: true, @@ -142,6 +126,7 @@ func (bridge *Bridge) installUpdate(ctx context.Context, job installJob) { Silent: job.silent, Error: err, }) + default: log.Info("The update was installed successfully")