Repository: syncthing/syncthing
File: cmd/syncthing/main.go (Go)

Code before:
			return
		}
		if err != nil {
			// Don't complain too loudly here; we might simply not have
			// internet connectivity, or the upgrade server might be down.
			slog.Info("Automatic upgrade", slogutil.Error(err))
			timer.Reset(checkInterval)
			continue
		}

		if upgrade.CompareVersions(rel.Tag, build.Version) != upgrade.Newer {
			// Skip equal, older or majorly newer (incompatible) versions
			timer.Reset(checkInterval)
			continue
		}

		slog.Info("Automatic upgrade", "current", build.Version, "latest", rel.Tag)
		err = upgrade.To(rel)
		if err != nil {
			slog.Error("Automatic upgrade failed", slogutil.Error(err))
			timer.Reset(checkInterval)
			continue
		}
		sub.Unsubscribe()
		restartDelay := time.Minute
		evLogger.Log(events.UpgradeRestartScheduled, map[string]interface{}{
			"delayS":     int(restartDelay / time.Second),
			"newVersion": rel.Tag,
		})
		slog.Error("Automatically upgraded, restarting in 1 minute", slog.String("newVersion", rel.Tag))
		time.Sleep(restartDelay)
		app.Stop(svcutil.ExitUpgrade)
		return
	}
}

func initialAutoUpgradeCheck(misc *db.Typed) (upgrade.Release, error) {
	if last, ok, err := misc.Time(upgradeCheckKey); err == nil && ok && time.Since(last) < upgradeCheckInterval {
		return upgrade.Release{}, errTooEarlyUpgradeCheck
	}
	_ = misc.PutTime(upgradeCheckKey, time.Now())
	release, err := checkUpgrade()
	if err != nil {
		return upgrade.Release{}, err
	}
	if upgrade.CompareVersions(release.Tag, build.Version) == upgrade.MajorNewer {
		return upgrade.Release{}, errors.New("higher major version")
	}

	if lastVersion, ok, err := misc.String(upgradeVersionKey); err == nil && ok && lastVersion == release.Tag {
		// Only check time if we try to upgrade to the same release.

Review comment (suggestion):
```suggestion
		evLogger.Log(events.UpgradeRestartScheduled, map[string]any{
```

Code after:
			return
		}
		if err != nil {
			// Don't complain too loudly here; we might simply not have
			// internet connectivity, or the upgrade server might be down.
			slog.Info("Automatic upgrade", slogutil.Error(err))
			timer.Reset(checkInterval)
			continue
		}

		if upgrade.CompareVersions(rel.Tag, build.Version) != upgrade.Newer {
			// Skip equal, older or majorly newer (incompatible) versions
			timer.Reset(checkInterval)
			continue
		}

		slog.Info("Automatic upgrade", "current", build.Version, "latest", rel.Tag)
		err = upgrade.To(rel)
		if err != nil {
			slog.Error("Automatic upgrade failed", slogutil.Error(err))
			timer.Reset(checkInterval)
			continue
		}
		sub.Unsubscribe()
		restartDelay := time.Minute
		evLogger.Log(events.UpgradeRestartScheduled, map[string]any{
			"delayS":     int(restartDelay / time.Second),
			"newVersion": rel.Tag,
		})
		slog.Error("Automatically upgraded, restarting in 1 minute", slog.String("newVersion", rel.Tag))
		time.Sleep(restartDelay)
		app.Stop(svcutil.ExitUpgrade)
		return
	}
}

func initialAutoUpgradeCheck(misc *db.Typed) (upgrade.Release, error) {
	if last, ok, err := misc.Time(upgradeCheckKey); err == nil && ok && time.Since(last) < upgradeCheckInterval {
		return upgrade.Release{}, errTooEarlyUpgradeCheck
	}
	_ = misc.PutTime(upgradeCheckKey, time.Now())
	release, err := checkUpgrade()
	if err != nil {
		return upgrade.Release{}, err
	}
	if upgrade.CompareVersions(release.Tag, build.Version) == upgrade.MajorNewer {
		return upgrade.Release{}, errors.New("higher major version")
	}

	if lastVersion, ok, err := misc.String(upgradeVersionKey); err == nil && ok && lastVersion == release.Tag {
		// Only check time if we try to upgrade to the same release.