From 958f51ace6f8572bed530912533ad6efb4212f2b Mon Sep 17 00:00:00 2001 From: Tommy van der Vorst Date: Mon, 25 Aug 2025 07:46:23 +0200 Subject: [PATCH] fix(cmd): only start temporary API server during migration if it's enabled (#10284) --- cmd/syncthing/main.go | 6 +++++- lib/syncthing/utils.go | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 57d64d3df..5f0154cc1 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -479,7 +479,11 @@ func (c *serveCmd) syncthingMain() { }) } - if err := syncthing.TryMigrateDatabase(ctx, c.DBDeleteRetentionInterval, cfgWrapper.GUI().Address()); err != nil { + var tempApiAddress string + if cfgWrapper.GUI().Enabled { + tempApiAddress = cfgWrapper.GUI().Address() + } + if err := syncthing.TryMigrateDatabase(ctx, c.DBDeleteRetentionInterval, tempApiAddress); err != nil { slog.Error("Failed to migrate old-style database", slogutil.Error(err)) os.Exit(1) } diff --git a/lib/syncthing/utils.go b/lib/syncthing/utils.go index 1fd646a9e..3d728ef4b 100644 --- a/lib/syncthing/utils.go +++ b/lib/syncthing/utils.go @@ -158,6 +158,7 @@ func OpenDatabase(path string, deleteRetention time.Duration) (db.DB, error) { } // Attempts migration of the old (LevelDB-based) database type to the new (SQLite-based) type +// This will attempt to provide a temporary API server during the migration, if `apiAddr` is not empty. func TryMigrateDatabase(ctx context.Context, deleteRetention time.Duration, apiAddr string) error { oldDBDir := locations.Get(locations.LegacyDatabase) if _, err := os.Lstat(oldDBDir); err != nil { @@ -173,10 +174,12 @@ func TryMigrateDatabase(ctx context.Context, deleteRetention time.Duration, apiA defer be.Close() // Start a temporary API server during the migration - api := migratingAPI{addr: apiAddr} - apiCtx, cancel := context.WithCancel(ctx) - defer cancel() - go api.Serve(apiCtx) + if apiAddr != "" { + api := migratingAPI{addr: apiAddr} + apiCtx, cancel := context.WithCancel(ctx) + defer cancel() + go api.Serve(apiCtx) + } sdb, err := sqlite.OpenForMigration(locations.Get(locations.Database)) if err != nil {