From f183d1cbec27f778dfe8e39c6f7db880bd09b9c5 Mon Sep 17 00:00:00 2001 From: xjtdy888 Date: Fri, 2 May 2025 02:36:35 +0800 Subject: [PATCH] chore(syncthing): ensure migrated database is closed before exiting (#10076) After opening the database, we performed some checks, such as whether the migration had already been successfully completed. If so, the function returned immediately, and the database was not closed. --------- Co-authored-by: Jakob Borg --- lib/syncthing/utils.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/syncthing/utils.go b/lib/syncthing/utils.go index e471a2403..9ab4b2ee3 100644 --- a/lib/syncthing/utils.go +++ b/lib/syncthing/utils.go @@ -170,11 +170,13 @@ func TryMigrateDatabase(deleteRetention time.Duration) error { // Apparently, not a valid old database return nil } + defer be.Close() sdb, err := sqlite.OpenForMigration(locations.Get(locations.Database)) if err != nil { return err } + defer sdb.Close() miscDB := db.NewMiscDB(sdb) if when, ok, err := miscDB.Time("migrated-from-leveldb-at"); err == nil && ok { @@ -265,8 +267,7 @@ func TryMigrateDatabase(deleteRetention time.Duration) error { _ = miscDB.PutTime("migrated-from-leveldb-at", time.Now()) _ = miscDB.PutString("migrated-from-leveldb-by", build.LongVersion) - be.Close() - sdb.Close() + _ = be.Close() _ = os.Rename(oldDBDir, oldDBDir+"-migrated") l.Infof("Migration complete, %d files and %dk blocks in %s", totFiles, totBlocks/1000, time.Since(t0).Truncate(time.Second))